| 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 |
| 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? |
| 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. |
| 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)) { |
| 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) { |
| 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; |
| 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); |
| 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 |
} |
} |
| 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. |
| 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. |