| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ValidVariableNameSniff implements Sniff |
||
| 13 | { |
||
| 14 | /** @var array */ |
||
| 15 | public $allowedNames = [ |
||
| 16 | '_GET', |
||
| 17 | '_POST', |
||
| 18 | '_COOKIE', |
||
| 19 | '_FILES', |
||
| 20 | '_REQUEST', |
||
| 21 | '_SERVER', |
||
| 22 | '_SESSION' |
||
| 23 | ]; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Listen to variable name tokens. |
||
| 27 | * |
||
| 28 | * @return int[] |
||
| 29 | */ |
||
| 30 | public function register() |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Check variable names to make sure no underscores are used. |
||
| 37 | * |
||
| 38 | * @param File $phpcsFile |
||
| 39 | * @param int $stackPtr |
||
| 40 | * |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | public function process(File $phpcsFile, $stackPtr) |
||
| 44 | { |
||
| 45 | $tokens = $phpcsFile->getTokens(); |
||
| 46 | $varName = ltrim($tokens[$stackPtr]['content'], '$'); |
||
| 47 | |||
| 48 | if (!in_array($varName, $this->allowedNames) |
||
| 49 | && preg_match('/^_/', $varName) |
||
| 50 | ) { |
||
| 51 | $phpcsFile->addWarning( |
||
| 52 | 'Variable names may not start with an underscore', |
||
| 53 | $stackPtr, |
||
| 54 | 'IllegalVariableNameUnderscore' |
||
| 59 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths