Skip to content

Commit ec196d0

Browse files
committed
Squiz/ClassFileName: bow out earlier for STDIN
As `STDIN` won't contain a usable file name, bow out and don't examine the input again. _Note: the `process()` method should really end on a `return $this->phpcsFile->numTokens;` as well as a file containing multiple classes should not get multiple contradicting errors, but that would require each test for this sniff to be in their own file, which I currently don't deem worth the effort._
1 parent 1a9128e commit ec196d0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Standards/Squiz/Sniffs/Classes/ClassFileNameSniff.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ public function register()
4343
*/
4444
public function process(File $phpcsFile, $stackPtr)
4545
{
46-
$fullPath = basename($phpcsFile->getFilename());
47-
$fileName = substr($fullPath, 0, strrpos($fullPath, '.'));
48-
if ($fileName === '') {
49-
// No filename probably means STDIN, so we can't do this check.
50-
return;
46+
$filename = $phpcsFile->getFilename();
47+
if ($filename === 'STDIN') {
48+
return $phpcsFile->numTokens;
5149
}
5250

51+
$fullPath = basename($filename);
52+
$fileName = substr($fullPath, 0, strrpos($fullPath, '.'));
53+
5354
$tokens = $phpcsFile->getTokens();
5455
$decName = $phpcsFile->findNext(T_STRING, $stackPtr);
5556

0 commit comments

Comments
 (0)