Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Common;
use PHP_CodeSniffer\Util\Tokens;

class ValidClassNameSniff implements Sniff
{
Expand Down Expand Up @@ -58,8 +59,8 @@ public function process(File $phpcsFile, $stackPtr)
// simply look for the first T_STRING because a class name
// starting with the number will be multiple tokens.
$opener = $tokens[$stackPtr]['scope_opener'];
$nameStart = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $opener, true);
$nameEnd = $phpcsFile->findNext([T_WHITESPACE, T_COLON], $nameStart, $opener);
$nameStart = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $opener, true);
$nameEnd = $phpcsFile->findNext((Tokens::$emptyTokens + [T_COLON => T_COLON]), $nameStart, $opener);
if ($nameEnd === false) {
$name = $tokens[$nameStart]['content'];
} else {
Expand All @@ -75,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
$type,
$name,
];
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data);
$phpcsFile->addError($error, $nameStart, 'NotCamelCaps', $data);
$phpcsFile->recordMetric($stackPtr, 'PascalCase class name', 'no');
} else {
$phpcsFile->recordMetric($stackPtr, 'PascalCase class name', 'yes');
Expand Down
10 changes: 10 additions & 0 deletions src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,13 @@ $foo = new class(
}
) extends DateTime {
};

class /*comment*/ CommentsShouldBeIgnoredValidName {}
trait //comment
commentsshouldbeignoredInvalidName {}
interface // phpcs:ignore Stnd.Cat.SniffName -- just testing
annotationshouldbeignored_InvalidName {}

class CommentsShouldBeIgnoredValid/*comment*/ {}
interface annotations_should_be_ignored_InvalidName// phpcs:ignore Stnd.Cat.SniffName -- just testing
{}
3 changes: 3 additions & 0 deletions src/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function getErrorList()
150 => 1,
151 => 1,
156 => 1,
195 => 1,
197 => 1,
200 => 1,
];

}//end getErrorList()
Expand Down
Loading