Skip to content
Snippets Groups Projects
Commit 7b3db8a7 authored by Eirik Morland's avatar Eirik Morland Committed by Klaus Purer
Browse files

fix(ClassFileName): Avoid running ClassFileNameSniff on text files (#3074186 by eriksm)

parent 318c900d
Branches
Tags
No related merge requests found
...@@ -57,17 +57,16 @@ class ClassFileNameSniff implements Sniff ...@@ -57,17 +57,16 @@ class ClassFileNameSniff implements Sniff
return ($phpcsFile->numTokens + 1); return ($phpcsFile->numTokens + 1);
} }
// If the file is not a php file, we do not care about how it looks,
// since we care about psr-4.
$extension = pathinfo($fullPath, PATHINFO_EXTENSION);
if ($extension !== 'php') {
return ($phpcsFile->numTokens + 1);
}
$tokens = $phpcsFile->getTokens(); $tokens = $phpcsFile->getTokens();
$decName = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); $decName = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
// Subcontext classes for Behat Drupal Extension are located in
// *.behat.inc files and should be named ModuleNameSubContext.
$isSubContext = preg_match('/\.behat$/', $fileName);
if ($isSubContext === 1) {
$fileName = preg_replace('/\.behat$/', '', $fileName);
$fileName = str_replace('_', '', ucwords($fileName, '_')).'SubContext';
}
if ($tokens[$decName]['code'] === T_STRING if ($tokens[$decName]['code'] === T_STRING
&& $tokens[$decName]['content'] !== $fileName && $tokens[$decName]['content'] !== $fileName
) { ) {
......
...@@ -27,6 +27,8 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest ...@@ -27,6 +27,8 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest
return []; return [];
case 'class_fle_name_test.module': case 'class_fle_name_test.module':
return []; return [];
case 'markdownFile.md':
return [];
} }
}//end getErrorList() }//end getErrorList()
...@@ -60,6 +62,7 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest ...@@ -60,6 +62,7 @@ class ClassFileNameUnitTest extends CoderSniffUnitTest
__DIR__.'/drupal8/ClassFileNameUnitTest.php', __DIR__.'/drupal8/ClassFileNameUnitTest.php',
__DIR__.'/drupal8/drupal8.behat.inc', __DIR__.'/drupal8/drupal8.behat.inc',
__DIR__.'/drupal7/class_fle_name_test.module', __DIR__.'/drupal7/class_fle_name_test.module',
__DIR__.'/drupal8/markdownFile.md',
]; ];
}//end getTestFiles() }//end getTestFiles()
......
this is not a php file
```php
<?php
/**
* Class.
*/
class Test {
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment