/[drupal]/contributions/modules/coder_tough_love/coder_tough_love.module
ViewVC logotype

Diff of /contributions/modules/coder_tough_love/coder_tough_love.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.5, Thu Nov 20 15:35:44 2008 UTC revision 1.1.2.6, Thu Jul 16 12:08:55 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: coder_tough_love.module,v 1.1.2.1 2008/11/19 16:26:31 morbus Exp $  // $Id: coder_tough_love.module,v 1.1.2.5 2008/11/20 15:35:44 morbus Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 159  function coder_tough_love_reviews() { Line 159  function coder_tough_love_reviews() {
159   * Administrative menu items should have a #description.   * Administrative menu items should have a #description.
160   */   */
161  function _coder_tough_love_admin_menu_descriptions(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_admin_menu_descriptions(&$coder_args, $review, $rule, $lines, &$results) {
162    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
163      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
164    
165      // are we inside a function that ends in _menu?      // are we inside a function that ends in _menu?
# Line 200  function _coder_tough_love_admin_menu_de Line 200  function _coder_tough_love_admin_menu_de
200   * If someone has defined Doxygen's param or return, they should document them.   * If someone has defined Doxygen's param or return, they should document them.
201   */   */
202  function _coder_tough_love_doxygen_params_explained(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_doxygen_params_explained(&$coder_args, $review, $rule, $lines, &$results) {
203    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
204      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
205      if (preg_match('/^ \* (@param|@return)/', $line)) {      if (preg_match('/^ \* (@param|@return)/', $line)) {
206        // check the next line to see if there's SOMETHING written.        // check the next line to see if there's SOMETHING written.
# Line 215  function _coder_tough_love_doxygen_param Line 215  function _coder_tough_love_doxygen_param
215   * Empty comments are not needed in a Doxygen block.   * Empty comments are not needed in a Doxygen block.
216   */   */
217  function _coder_tough_love_doxygen_function_empty_comment(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_doxygen_function_empty_comment(&$coder_args, $review, $rule, $lines, &$results) {
218    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
219      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
220    
221      if (preg_match('/^ \*\/$/', $line)) {      if (preg_match('/^ \*\/$/', $line)) {
# Line 231  function _coder_tough_love_doxygen_funct Line 231  function _coder_tough_love_doxygen_funct
231   * Function documentation should be less than 80 characters per line.   * Function documentation should be less than 80 characters per line.
232   */   */
233  function _coder_tough_love_doxygen_function_long_line(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_doxygen_function_long_line(&$coder_args, $review, $rule, $lines, &$results) {
234    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
235      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
236    
237      if (preg_match('/^ \*/', $line) && drupal_strlen($line) > 80) {      if (preg_match('/^ \*/', $line) && drupal_strlen($line) > 80) {
# Line 244  function _coder_tough_love_doxygen_funct Line 244  function _coder_tough_love_doxygen_funct
244   * The first line of a function Doxygen should be a brief summary.   * The first line of a function Doxygen should be a brief summary.
245   */   */
246  function _coder_tough_love_doxygen_function_one_line_summary(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_doxygen_function_one_line_summary(&$coder_args, $review, $rule, $lines, &$results) {
247    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
248      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
249      if (preg_match('/^\/\*\*$/', $line)) {      if (preg_match('/^\/\*\*$/', $line)) {
250        $first_line_exists = $second_line_is_ok = 0;        $first_line_exists = $second_line_is_ok = 0;
# Line 299  function _coder_tough_love_pspell_check( Line 299  function _coder_tough_love_pspell_check(
299        }        }
300      }      }
301    
302      foreach ($lines as $line_number => $line) {      foreach ((array)$lines as $line_number => $line) {
303        $line = implode(' ', $line); // concat'd parts.        $line = implode(' ', $line); // concat'd parts.
304        $found_unknown_word = 0; // start fresh please.        $found_unknown_word = 0; // start fresh please.
305        $line = coder_tough_love_remove_known_keys($line);        $line = coder_tough_love_remove_known_keys($line);
# Line 307  function _coder_tough_love_pspell_check( Line 307  function _coder_tough_love_pspell_check(
307        $line = coder_tough_love_remove_sql_queries($line);        $line = coder_tough_love_remove_sql_queries($line);
308        $line = trim($line); // any fidgety whitespace.        $line = trim($line); // any fidgety whitespace.
309    
310        $words = explode(' ', $line);        $words = preg_split('/\s+/', $line);
311    
312        foreach ($words as $word) {        foreach ($words as $word) {
313          if (!pspell_check($pspell_link, drupal_strtolower(trim($word)))) {          // only look for words longer than 2 letters. could allow some misses, but reduces fositives.
314            if (drupal_strlen($word) > 2 && !pspell_check($pspell_link, drupal_strtolower(trim($word)))) {
315            $found_unknown_word = 1; // don't spit the error yet...            $found_unknown_word = 1; // don't spit the error yet...
316          }          }
317        }        }
# Line 327  function _coder_tough_love_pspell_check( Line 329  function _coder_tough_love_pspell_check(
329  function _coder_tough_love_sentence_style(&$coder_args, $review, $rule, $lines, &$results) {  function _coder_tough_love_sentence_style(&$coder_args, $review, $rule, $lines, &$results) {
330    $filename_to_title_caps = ucwords(str_replace('_', ' ', preg_replace('/(.*?)(\..*)/', '\1', basename($coder_args['#filename']))));    $filename_to_title_caps = ucwords(str_replace('_', ' ', preg_replace('/(.*?)(\..*)/', '\1', basename($coder_args['#filename']))));
331    
332    foreach ($lines as $line_number => $line) {    foreach ((array)$lines as $line_number => $line) {
333      $line = implode(' ', $line); // concat'd parts.      $line = implode(' ', $line); // concat'd parts.
334      $line = coder_tough_love_remove_known_keys($line);      $line = coder_tough_love_remove_known_keys($line);
335      $line = trim($line); // any fidgety whitespace left.      $line = trim($line); // any fidgety whitespace left.
# Line 385  function coder_tough_love_remove_known_k Line 387  function coder_tough_love_remove_known_k
387   */   */
388  function coder_tough_love_remove_non_words($line) {  function coder_tough_love_remove_non_words($line) {
389    // attempt to remove ending punctuation from a sentence.    // attempt to remove ending punctuation from a sentence.
390      $line = preg_replace("/\w+\.\w+/", "", $line); // remove table.column type strings.
391    $line = preg_replace("/(\w)[:;,\.\?\!](\s|$)/", "\1", $line); // remove ending punctuation.    $line = preg_replace("/(\w)[:;,\.\?\!](\s|$)/", "\1", $line); // remove ending punctuation.
392    $line = preg_replace("/\s+([@%!\$].*?)(\s|$)/", ' ', $line); // remove %placeholders in line.    $line = preg_replace("/\s+([@%!\$].*?)(\s|$)/", ' ', $line); // remove %placeholders in line.
393    $line = preg_replace("/\.\w+/", '', $line); // filename extensions leftover from previous.    $line = preg_replace("/\.\w+/", '', $line); // filename extensions leftover from previous.

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.1.2.6

  ViewVC Help
Powered by ViewVC 1.1.2