Skip to content
Snippets Groups Projects
Unverified Commit de37d530 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

feat(ClassComment): Add a sniff to check for "Class Example" doc comments (#3156856 by Arkener)

parent 73756944
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -8,3 +8,17 @@
trait Bingo {
}
/**
* Trait Bongo
*/
trait Bongo {
}
/**
* Trait Bango.
*/
trait Bango {
}
......@@ -11,3 +11,17 @@
trait Bingo {
}
/**
* Trait Bongo.
*/
trait Bongo {
}
/**
* Trait Bango.
*/
trait Bango {
}
......@@ -37,7 +37,10 @@ class ClassCommentUnitTest extends CoderSniffUnitTest
*/
protected function getWarningList(string $testFile): array
{
return [];
return [
14 => 1,
21 => 1,
];
}//end getWarningList()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment