coder.module function one line summary

  1.    array(
  2.       '#source' => 'all',
  3.       '#type' => 'callback',
  4.       '#value' => '_coder_doxygen_function_one_line_summary',
  5.       '#warning_callback' => '_coder_doxygen_function_one_line_summary_warning',
  6.     ),
  7.  
  8.  
  9. /**
  10.  * The first line of a function Doxygen should be a brief summary.
  11.  * and this should fail miserably.
  12.  */
  13. function _coder_doxygen_function_one_line_summary(&$coder_args, $review, $rule, $lines, &$results) {
  14.   foreach ($lines as $line_number => $line) {
  15.     if (preg_match('/^\/\*\*$/', $line)) {
  16.       $first_line_exists = $second_line_is_ok = 0;
  17.  
  18.       // check the next line to see if there's SOMETHING written.
  19.       if (preg_match('/^ \* (\w+)/', $lines[$line_number + 1])) {
  20.         $first_line_exists = $line_number + 1; // used in _coder_error().
  21.       }
  22.  
  23.       // and check the line after that for either a blank line or end.
  24.       if ($first_line_exists && preg_match('/^( \*\/| \*\/)$/', $lines[$line_number + 2])) {
  25.         $second_line_is_ok = 1;
  26.       }
  27.     }
  28.  
  29.     if (preg_match('/^function/', $line) && preg_match('/^ \*\/$/', $lines[$line_number - 1])) {
  30.       if (!$second_line_is_ok) { // we use $first_line_exists, not $line_number, to refer to start of doxygen.
  31.         _coder_error($results, $rule, _coder_severity_name($coder_args, $review, $rule), $first_line_exists);
  32.         $first_line_exists = $second_line_is_ok = 0;
  33.       }
  34.     }
  35.   }
  36. }
  37.  
  38. function _coder_doxygen_function_one_line_summary_warning() {
  39.   return array(
  40.     '#warning' => t('Function summaries should be one line only.'),
  41.     '#link' => 'http://drupal.org/node/1354',
  42.   );
  43. }