@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function register(): array |
| 19 | 19 | { |
| 20 | - return [T_ELSE, T_ELSEIF]; |
|
| 20 | + return [ T_ELSE, T_ELSEIF ]; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -30,6 +30,6 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 32 | 32 | { |
| 33 | - $phpcsFile->addError('Do not use "else" or "elseif"', $stackPtr, __CLASS__); |
|
| 33 | + $phpcsFile->addError('Do not use "else" or "elseif"', $stackPtr, __CLASS__); |
|
| 34 | 34 | } |
| 35 | 35 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function register(): array |
| 16 | 16 | { |
| 17 | - return [T_IF]; |
|
| 17 | + return [ T_IF ]; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | $this->phpcsFile = $phpcsFile; |
| 43 | 43 | $tokens = $phpcsFile->getTokens(); |
| 44 | - $token = $tokens[$stackPtr]; |
|
| 45 | - $start = $token['scope_opener']; |
|
| 46 | - $end = $token['scope_closer']; |
|
| 44 | + $token = $tokens[ $stackPtr ]; |
|
| 45 | + $start = $token[ 'scope_opener' ]; |
|
| 46 | + $end = $token[ 'scope_closer' ]; |
|
| 47 | 47 | |
| 48 | - $this->errorStack = []; |
|
| 49 | - for ($index=$start; $index <= $end; $index++) { |
|
| 50 | - $this->checkForNestedIf($tokens[$index], $stackPtr); |
|
| 48 | + $this->errorStack = [ ]; |
|
| 49 | + for ($index = $start; $index <= $end; $index++) { |
|
| 50 | + $this->checkForNestedIf($tokens[ $index ], $stackPtr); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | protected function checkForNestedIf(array $token, int $stackPtr) |
| 61 | 61 | { |
| 62 | - if (! $this->isIfStatement($token)) { |
|
| 62 | + if (!$this->isIfStatement($token)) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $this->phpcsFile->addError('Nested if statement found.', $stackPtr, __CLASS__); |
| 71 | - $this->errorStack[] = $stackPtr; |
|
| 71 | + $this->errorStack[ ] = $stackPtr; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | protected function isIfStatement(array $token): bool |
| 95 | 95 | { |
| 96 | - if ($token['type'] === 'T_IF') { |
|
| 96 | + if ($token[ 'type' ] === 'T_IF') { |
|
| 97 | 97 | return true; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function register(): array |
| 16 | 16 | { |
| 17 | - return [T_RETURN]; |
|
| 17 | + return [ T_RETURN ]; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | $returnTokenIndex = $stackPtr; |
| 31 | 31 | |
| 32 | 32 | $scope = array_slice($tokens, $returnTokenIndex, null, true); |
| 33 | - $semicolons = array_filter($scope, function ($token) { |
|
| 34 | - return $token['type'] === 'T_SEMICOLON'; |
|
| 33 | + $semicolons = array_filter($scope, function($token) { |
|
| 34 | + return $token[ 'type' ] === 'T_SEMICOLON'; |
|
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | 37 | $returnValueIndex = key($semicolons) - 1; |
| 38 | 38 | |
| 39 | - if ($scope[$returnValueIndex]['type'] === 'T_NULL') { |
|
| 39 | + if ($scope[ $returnValueIndex ][ 'type' ] === 'T_NULL') { |
|
| 40 | 40 | $error = "Return null value found."; |
| 41 | 41 | $phpcsFile->addError($error, $returnValueIndex, __CLASS__); |
| 42 | 42 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function register(): array |
| 22 | 22 | { |
| 23 | - return [T_FUNCTION]; |
|
| 23 | + return [ T_FUNCTION ]; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -34,21 +34,21 @@ discard block |
||
| 34 | 34 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 35 | 35 | { |
| 36 | 36 | $tokens = $phpcsFile->getTokens(); |
| 37 | - $token = $tokens[$stackPtr]; |
|
| 38 | - $openParenIndex = $token['parenthesis_opener']; |
|
| 39 | - $closedParenIndex = $token['parenthesis_closer']; |
|
| 37 | + $token = $tokens[ $stackPtr ]; |
|
| 38 | + $openParenIndex = $token[ 'parenthesis_opener' ]; |
|
| 39 | + $closedParenIndex = $token[ 'parenthesis_closer' ]; |
|
| 40 | 40 | |
| 41 | 41 | $numberOfParameters = 0; |
| 42 | - for ($index=$openParenIndex+1; $index <= $closedParenIndex; $index++) { |
|
| 43 | - $tokens[$index]['type'] == 'T_VARIABLE' ? $numberOfParameters++ : null; |
|
| 42 | + for ($index = $openParenIndex + 1; $index <= $closedParenIndex; $index++) { |
|
| 43 | + $tokens[ $index ][ 'type' ] == 'T_VARIABLE' ? $numberOfParameters++ : null; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($numberOfParameters > $this->maxParameters) { |
| 47 | - $phpcsFile->addError("Function has more than {$this->maxParameters} parameters. Please reduce.", $stackPtr, __CLASS__ . 'MoreThan'); |
|
| 47 | + $phpcsFile->addError("Function has more than {$this->maxParameters} parameters. Please reduce.", $stackPtr, __CLASS__.'MoreThan'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | if ($numberOfParameters == $this->maxParameters) { |
| 51 | - $phpcsFile->addWarning("Function has {$this->maxParameters} parameters.", $stackPtr, __CLASS__ . 'hasMax'); |
|
| 51 | + $phpcsFile->addWarning("Function has {$this->maxParameters} parameters.", $stackPtr, __CLASS__.'hasMax'); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * The two token types we're looking for. |
| 13 | 13 | * @var array |
| 14 | 14 | */ |
| 15 | - protected $booleans = ['T_FALSE', 'T_TRUE']; |
|
| 15 | + protected $booleans = [ 'T_FALSE', 'T_TRUE' ]; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Returns the token types that this sniff is interested in. |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function register(): array |
| 22 | 22 | { |
| 23 | - return [T_FUNCTION]; |
|
| 23 | + return [ T_FUNCTION ]; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $tokens = $phpcsFile->getTokens(); |
| 37 | 37 | |
| 38 | - $token = $tokens[$stackPtr]; |
|
| 39 | - $openParenIndex = $token['parenthesis_opener']; |
|
| 40 | - $closedParenIndex = $token['parenthesis_closer']; |
|
| 38 | + $token = $tokens[ $stackPtr ]; |
|
| 39 | + $openParenIndex = $token[ 'parenthesis_opener' ]; |
|
| 40 | + $closedParenIndex = $token[ 'parenthesis_closer' ]; |
|
| 41 | 41 | |
| 42 | - for ($index=$openParenIndex+1; $index <= $closedParenIndex; $index++) { |
|
| 43 | - if (in_array($tokens[$index]['type'], $this->booleans)) { |
|
| 42 | + for ($index = $openParenIndex + 1; $index <= $closedParenIndex; $index++) { |
|
| 43 | + if (in_array($tokens[ $index ][ 'type' ], $this->booleans)) { |
|
| 44 | 44 | $phpcsFile->addError("Function/method contains a flag parameter.", $stackPtr, __CLASS__); |
| 45 | 45 | continue; |
| 46 | 46 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function register(): array |
| 16 | 16 | { |
| 17 | - return [T_FUNCTION]; |
|
| 17 | + return [ T_FUNCTION ]; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -27,20 +27,20 @@ discard block |
||
| 27 | 27 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 28 | 28 | { |
| 29 | 29 | $tokens = $phpcsFile->getTokens(); |
| 30 | - if (! isset($tokens[$stackPtr]['scope_closer'])) { |
|
| 30 | + if (!isset($tokens[ $stackPtr ][ 'scope_closer' ])) { |
|
| 31 | 31 | return; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - $endOfMethodIndex = $tokens[$stackPtr]['scope_closer']; |
|
| 34 | + $endOfMethodIndex = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
| 35 | 35 | |
| 36 | - for ($index=$endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
|
| 37 | - if ($tokens[$index]['type'] !== 'T_WHITESPACE') { |
|
| 38 | - $nextCodeLine = $tokens[$index]['line']; |
|
| 36 | + for ($index = $endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
|
| 37 | + if ($tokens[ $index ][ 'type' ] !== 'T_WHITESPACE') { |
|
| 38 | + $nextCodeLine = $tokens[ $index ][ 'line' ]; |
|
| 39 | 39 | break; |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $linesBetween = $nextCodeLine - $tokens[$endOfMethodIndex]['line'] - 1; |
|
| 43 | + $linesBetween = $nextCodeLine - $tokens[ $endOfMethodIndex ][ 'line' ] - 1; |
|
| 44 | 44 | |
| 45 | 45 | if ($linesBetween > 1) { |
| 46 | 46 | $phpcsFile->addError("No more than 1 line after a method/function is allowed.", $stackPtr, __CLASS__); |