@@ -12,7 +12,7 @@ |
||
12 | 12 | { |
13 | 13 | public function register() |
14 | 14 | { |
15 | - return [T_ELSE, T_ELSEIF]; |
|
15 | + return [ T_ELSE, T_ELSEIF ]; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -12,25 +12,25 @@ |
||
12 | 12 | |
13 | 13 | public function register() |
14 | 14 | { |
15 | - return [T_FUNCTION]; |
|
15 | + return [ T_FUNCTION ]; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
19 | 19 | { |
20 | 20 | $tokens = $phpcsFile->getTokens(); |
21 | - $token = $tokens[$stackPtr]; |
|
21 | + $token = $tokens[ $stackPtr ]; |
|
22 | 22 | |
23 | 23 | // Skip function without body. |
24 | - if (isset($token['scope_opener']) === false) { |
|
24 | + if (isset($token[ 'scope_opener' ]) === false) { |
|
25 | 25 | return 0; |
26 | 26 | } |
27 | 27 | |
28 | - $firstToken = $tokens[$token['scope_opener']]; |
|
29 | - $lastToken = $tokens[$token['scope_closer']]; |
|
30 | - $length = $lastToken['line'] - $firstToken['line']; |
|
28 | + $firstToken = $tokens[ $token[ 'scope_opener' ] ]; |
|
29 | + $lastToken = $tokens[ $token[ 'scope_closer' ] ]; |
|
30 | + $length = $lastToken[ 'line' ] - $firstToken[ 'line' ]; |
|
31 | 31 | |
32 | 32 | if ($length > $this->maxLength) { |
33 | - $tokenType = strtolower(substr($token['type'], 2)); |
|
33 | + $tokenType = strtolower(substr($token[ 'type' ], 2)); |
|
34 | 34 | $error = "Function is {$length} lines. Must be {$this->maxLength} lines or fewer."; |
35 | 35 | $phpcsFile->addError($error, $stackPtr, sprintf('%sTooBig', ucfirst($tokenType))); |
36 | 36 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function register() |
16 | 16 | { |
17 | - return [T_RETURN]; |
|
17 | + return [ T_RETURN ]; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | $returnValueToken = ''; |
34 | 34 | for ($index = $returnTokenIndex; $index < count($tokens); $index++) { |
35 | - if ($tokens[$index]['type'] === 'T_SEMICOLON') { |
|
36 | - $returnValueToken = $tokens[$index - 1]; |
|
35 | + if ($tokens[ $index ][ 'type' ] === 'T_SEMICOLON') { |
|
36 | + $returnValueToken = $tokens[ $index - 1 ]; |
|
37 | 37 | break; |
38 | 38 | } |
39 | 39 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - if ($returnValueToken['type'] === 'T_NULL') { |
|
45 | + if ($returnValueToken[ 'type' ] === 'T_NULL') { |
|
46 | 46 | $error = "Return null value found."; |
47 | 47 | $phpcsFile->addError($error, $stackPtr); |
48 | 48 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function register() |
23 | 23 | { |
24 | - return [T_CLASS]; |
|
24 | + return [ T_CLASS ]; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
36 | 36 | { |
37 | 37 | $tokens = $phpcsFile->getTokens(); |
38 | - $token = $tokens[$stackPtr]; |
|
38 | + $token = $tokens[ $stackPtr ]; |
|
39 | 39 | |
40 | - $openParenthesis = $tokens[$token['scope_opener']]; |
|
41 | - $closedParenthesis = $tokens[$token['scope_closer']]; |
|
40 | + $openParenthesis = $tokens[ $token[ 'scope_opener' ] ]; |
|
41 | + $closedParenthesis = $tokens[ $token[ 'scope_closer' ] ]; |
|
42 | 42 | |
43 | - $length = $closedParenthesis['line'] - $openParenthesis['line']; |
|
43 | + $length = $closedParenthesis[ 'line' ] - $openParenthesis[ 'line' ]; |
|
44 | 44 | |
45 | 45 | if ($length > $this->maxLength) { |
46 | 46 | $phpcsFile->addError("Class is {$length} lines. Must be {$this->maxLength} lines or fewer.", $stackPtr); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * The forbidden strings this sniff looks for. |
13 | 13 | * @var array |
14 | 14 | */ |
15 | - protected $keywords = ['And', '_and', 'Or', '_or']; |
|
15 | + protected $keywords = [ 'And', '_and', 'Or', '_or' ]; |
|
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() |
22 | 22 | { |
23 | - return [T_FUNCTION]; |
|
23 | + return [ T_FUNCTION ]; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
35 | 35 | { |
36 | 36 | $tokens = $phpcsFile->getTokens(); |
37 | - $functionNameToken = $tokens[$stackPtr + 2]; |
|
38 | - $functionName = $functionNameToken['content']; |
|
37 | + $functionNameToken = $tokens[ $stackPtr + 2 ]; |
|
38 | + $functionName = $functionNameToken[ 'content' ]; |
|
39 | 39 | |
40 | - if (! $this->containsKeywords($functionName)) { |
|
40 | + if (!$this->containsKeywords($functionName)) { |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function register() |
27 | 27 | { |
28 | - return [T_FUNCTION, T_CLOSURE, T_SWITCH]; |
|
28 | + return [ T_FUNCTION, T_CLOSURE, T_SWITCH ]; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
40 | 40 | { |
41 | 41 | $tokens = $phpcsFile->getTokens(); |
42 | - $token = $tokens[$stackPtr]; |
|
42 | + $token = $tokens[ $stackPtr ]; |
|
43 | 43 | $this->maxIndentationFound = 0; |
44 | 44 | |
45 | 45 | // Ignore functions with no body |
46 | - if (isset($token['scope_opener']) === false) { |
|
46 | + if (isset($token[ 'scope_opener' ]) === false) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function inspectScope(array $token, array $tokens) |
67 | 67 | { |
68 | - $start = $token['scope_opener']; |
|
69 | - $end = $token['scope_closer']; |
|
70 | - $this->relativeScopeLevel = $tokens[$start]['level']; |
|
71 | - for ($index=$start; $index <= $end; $index++) { |
|
72 | - $nestedToken = $tokens[$index]; |
|
73 | - if ($nestedToken['type'] === "T_SWITCH") { |
|
68 | + $start = $token[ 'scope_opener' ]; |
|
69 | + $end = $token[ 'scope_closer' ]; |
|
70 | + $this->relativeScopeLevel = $tokens[ $start ][ 'level' ]; |
|
71 | + for ($index = $start; $index <= $end; $index++) { |
|
72 | + $nestedToken = $tokens[ $index ]; |
|
73 | + if ($nestedToken[ 'type' ] === "T_SWITCH") { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | $this->adjustMaxIndentationFound($nestedToken); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function adjustMaxIndentationFound(array $nestedToken) |
87 | 87 | { |
88 | - $tokenNestedLevel = $nestedToken['level']; |
|
88 | + $tokenNestedLevel = $nestedToken[ 'level' ]; |
|
89 | 89 | $nestedLevel = $tokenNestedLevel - $this->relativeScopeLevel; |
90 | 90 | $nestedLevel > $this->maxIndentationFound ? $this->maxIndentationFound = $nestedLevel : null; |
91 | 91 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | // indentation limit. |
102 | 102 | $indentationFound = $this->maxIndentationFound - 1; |
103 | 103 | $indentationLimit = $this->indentationLimit - 1; |
104 | - return "{$indentationFound} indenation levels found. " . |
|
104 | + return "{$indentationFound} indenation levels found. ". |
|
105 | 105 | "Maximum of {$indentationLimit} indenation levels allowed."; |
106 | 106 | } |
107 | 107 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function register() |
22 | 22 | { |
23 | - return [T_FUNCTION]; |
|
23 | + return [ T_FUNCTION ]; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -34,13 +34,13 @@ 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) { |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns the token types that this sniff is interested in. |
13 | - * @return array |
|
13 | + * @return integer[] |
|
14 | 14 | */ |
15 | 15 | public function register() |
16 | 16 | { |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function register() |
16 | 16 | { |
17 | - return [T_IF]; |
|
17 | + return [ T_IF ]; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | { |
30 | 30 | $this->phpcsFile = $phpcsFile; |
31 | 31 | $tokens = $phpcsFile->getTokens(); |
32 | - $token = $tokens[$stackPtr]; |
|
33 | - $start = $token['scope_opener']; |
|
34 | - $end = $token['scope_closer']; |
|
32 | + $token = $tokens[ $stackPtr ]; |
|
33 | + $start = $token[ 'scope_opener' ]; |
|
34 | + $end = $token[ 'scope_closer' ]; |
|
35 | 35 | |
36 | - $this->errorStack = []; |
|
37 | - for ($index=$start; $index <= $end; $index++) { |
|
38 | - $this->checkForNestedIf($tokens[$index], $stackPtr); |
|
36 | + $this->errorStack = [ ]; |
|
37 | + for ($index = $start; $index <= $end; $index++) { |
|
38 | + $this->checkForNestedIf($tokens[ $index ], $stackPtr); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | protected function checkForNestedIf(array $token, $stackPtr) |
49 | 49 | { |
50 | - if (! $this->isIfStatement($token)) { |
|
50 | + if (!$this->isIfStatement($token)) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | $this->phpcsFile->addError('Nested if statement found.', $stackPtr); |
59 | - $this->errorStack[] = $stackPtr; |
|
59 | + $this->errorStack[ ] = $stackPtr; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function isIfStatement(array $token) |
83 | 83 | { |
84 | - if ($token['type'] === 'T_IF') { |
|
84 | + if ($token[ 'type' ] === 'T_IF') { |
|
85 | 85 | return true; |
86 | 86 | } |
87 | 87 |