@@ -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); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * The loop tokens we're lookin for. |
| 13 | 13 | * @var array |
| 14 | 14 | */ |
| 15 | - protected $loops = ['T_FOR', 'T_FOREACH', 'T_WHILE']; |
|
| 15 | + protected $loops = [ 'T_FOR', 'T_FOREACH', 'T_WHILE' ]; |
|
| 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 | /** |
@@ -34,18 +34,18 @@ discard block |
||
| 34 | 34 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 35 | 35 | { |
| 36 | 36 | $tokens = $phpcsFile->getTokens(); |
| 37 | - $token = $tokens[$stackPtr]; |
|
| 38 | - $functionNameToken = $tokens[$stackPtr + 2]; |
|
| 39 | - $functionName = $functionNameToken['content']; |
|
| 37 | + $token = $tokens[ $stackPtr ]; |
|
| 38 | + $functionNameToken = $tokens[ $stackPtr + 2 ]; |
|
| 39 | + $functionName = $functionNameToken[ 'content' ]; |
|
| 40 | 40 | if ($functionName !== '__construct') { |
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $startIndex = $token['scope_opener']; |
|
| 45 | - $endIndex = $token['scope_closer']; |
|
| 44 | + $startIndex = $token[ 'scope_opener' ]; |
|
| 45 | + $endIndex = $token[ 'scope_closer' ]; |
|
| 46 | 46 | |
| 47 | - for ($index=$startIndex; $index <= $endIndex; $index++) { |
|
| 48 | - if (in_array($tokens[$index]['type'], $this->loops)) { |
|
| 47 | + for ($index = $startIndex; $index <= $endIndex; $index++) { |
|
| 48 | + if (in_array($tokens[ $index ][ 'type' ], $this->loops)) { |
|
| 49 | 49 | $phpcsFile->addError("Class constructor cannot contain a loop.", $stackPtr); |
| 50 | 50 | continue; |
| 51 | 51 | } |