Loading coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php +25 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,31 @@ class ClassCommentSniff implements Sniff } } $comment = []; for ($i = $start; $i < $commentEnd; $i++) { if ($tokens[$i]['code'] === T_DOC_COMMENT_TAG) { break; } if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { $comment[] = $tokens[$i]['content']; } } $words = explode(' ', implode(' ', $comment)); if (count($words) <= 2) { $className = $phpcsFile->getDeclarationName($stackPtr); foreach ($words as $word) { // Check if the comment contains the class name. if (strpos($word, $className) !== false) { $error = 'The class short comment should describe what the class does and not simply repeat the class name'; $phpcsFile->addWarning($error, $commentEnd, 'Short'); break; } } } }//end process() Loading tests/Drupal/Commenting/ClassCommentUnitTest.inc +14 −0 Original line number Diff line number Diff line Loading @@ -8,3 +8,17 @@ trait Bingo { } /** * Trait Bongo */ trait Bongo { } /** * Trait Bango. */ trait Bango { } tests/Drupal/Commenting/ClassCommentUnitTest.inc.fixed +14 −0 Original line number Diff line number Diff line Loading @@ -11,3 +11,17 @@ trait Bingo { } /** * Trait Bongo. */ trait Bongo { } /** * Trait Bango. */ trait Bango { } tests/Drupal/Commenting/ClassCommentUnitTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,10 @@ class ClassCommentUnitTest extends CoderSniffUnitTest */ protected function getWarningList(string $testFile): array { return []; return [ 14 => 1, 21 => 1, ]; }//end getWarningList() Loading Loading
coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php +25 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,31 @@ class ClassCommentSniff implements Sniff } } $comment = []; for ($i = $start; $i < $commentEnd; $i++) { if ($tokens[$i]['code'] === T_DOC_COMMENT_TAG) { break; } if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { $comment[] = $tokens[$i]['content']; } } $words = explode(' ', implode(' ', $comment)); if (count($words) <= 2) { $className = $phpcsFile->getDeclarationName($stackPtr); foreach ($words as $word) { // Check if the comment contains the class name. if (strpos($word, $className) !== false) { $error = 'The class short comment should describe what the class does and not simply repeat the class name'; $phpcsFile->addWarning($error, $commentEnd, 'Short'); break; } } } }//end process() Loading
tests/Drupal/Commenting/ClassCommentUnitTest.inc +14 −0 Original line number Diff line number Diff line Loading @@ -8,3 +8,17 @@ trait Bingo { } /** * Trait Bongo */ trait Bongo { } /** * Trait Bango. */ trait Bango { }
tests/Drupal/Commenting/ClassCommentUnitTest.inc.fixed +14 −0 Original line number Diff line number Diff line Loading @@ -11,3 +11,17 @@ trait Bingo { } /** * Trait Bongo. */ trait Bongo { } /** * Trait Bango. */ trait Bango { }
tests/Drupal/Commenting/ClassCommentUnitTest.php +4 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,10 @@ class ClassCommentUnitTest extends CoderSniffUnitTest */ protected function getWarningList(string $testFile): array { return []; return [ 14 => 1, 21 => 1, ]; }//end getWarningList() Loading