Loading coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +14 −0 Original line number Diff line number Diff line Loading @@ -111,8 +111,22 @@ class HookCommentSniff implements Sniff } } }//end if return; }//end if // Check if the doc block just repeats the function name with // "Implements example_hook_name()". $functionName = $phpcsFile->getDeclarationName($stackPtr); if ($functionName !== null && preg_match("/^[\s]*Implements $functionName\(\)\.$/i", $shortContent) === 1) { $error = 'Hook implementations must be documented with "Implements hook_example()."'; $fix = $phpcsFile->addFixableError($error, $short, 'HookRepeat'); if ($fix === true) { $newComment = preg_replace('/Implements [^_]+/', 'Implements hook', $shortContent); $phpcsFile->fixer->replaceToken($short, $newComment); } } }//end process() Loading coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php /** * @file * Example file with hook implementations. */ /** * Implements example_page_build(). */ function example_page_build(&$page) { } coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc.fixed 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php /** * @file * Example file with hook implementations. */ /** * Implements hook_page_build(). */ function example_page_build(&$page) { } coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.php 0 → 100644 +42 −0 Original line number Diff line number Diff line <?php namespace Drupal\Sniffs\Commenting; use Drupal\Test\CoderSniffUnitTest; class HookCommentUnitTest extends CoderSniffUnitTest { /** * Returns the lines where errors should occur. * * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @return array(int => int) */ public function getErrorList($testFile = NULL) { return array( 9 => 1, ); }//end getErrorList() /** * Returns the lines where warnings should occur. * * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @return array(int => int) */ public function getWarningList($testFile = NULL) { return array(); }//end getWarningList() }//end class Loading
coder_sniffer/Drupal/Sniffs/Commenting/HookCommentSniff.php +14 −0 Original line number Diff line number Diff line Loading @@ -111,8 +111,22 @@ class HookCommentSniff implements Sniff } } }//end if return; }//end if // Check if the doc block just repeats the function name with // "Implements example_hook_name()". $functionName = $phpcsFile->getDeclarationName($stackPtr); if ($functionName !== null && preg_match("/^[\s]*Implements $functionName\(\)\.$/i", $shortContent) === 1) { $error = 'Hook implementations must be documented with "Implements hook_example()."'; $fix = $phpcsFile->addFixableError($error, $short, 'HookRepeat'); if ($fix === true) { $newComment = preg_replace('/Implements [^_]+/', 'Implements hook', $shortContent); $phpcsFile->fixer->replaceToken($short, $newComment); } } }//end process() Loading
coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php /** * @file * Example file with hook implementations. */ /** * Implements example_page_build(). */ function example_page_build(&$page) { }
coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.inc.fixed 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php /** * @file * Example file with hook implementations. */ /** * Implements hook_page_build(). */ function example_page_build(&$page) { }
coder_sniffer/Drupal/Test/Commenting/HookCommentUnitTest.php 0 → 100644 +42 −0 Original line number Diff line number Diff line <?php namespace Drupal\Sniffs\Commenting; use Drupal\Test\CoderSniffUnitTest; class HookCommentUnitTest extends CoderSniffUnitTest { /** * Returns the lines where errors should occur. * * The key of the array should represent the line number and the value * should represent the number of errors that should occur on that line. * * @return array(int => int) */ public function getErrorList($testFile = NULL) { return array( 9 => 1, ); }//end getErrorList() /** * Returns the lines where warnings should occur. * * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * * @return array(int => int) */ public function getWarningList($testFile = NULL) { return array(); }//end getWarningList() }//end class