@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\Syntax; |
4 | 4 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function register(): array |
16 | 16 | { |
17 | - return [T_ISSET]; |
|
17 | + return [ T_ISSET ]; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | $semiColinFound = false; |
56 | 56 | |
57 | 57 | while (true) { |
58 | - if ($tokens[$index]['type'] == 'T_SEMICOLON') { |
|
58 | + if ($tokens[ $index ][ 'type' ] == 'T_SEMICOLON') { |
|
59 | 59 | break; |
60 | 60 | } |
61 | 61 | |
62 | - if ($tokens[$index]['type'] == 'T_INLINE_THEN') { |
|
62 | + if ($tokens[ $index ][ 'type' ] == 'T_INLINE_THEN') { |
|
63 | 63 | $questionMarkFound = true; |
64 | 64 | } |
65 | 65 | |
66 | - if ($tokens[$index]['type'] == 'T_INLINE_ELSE') { |
|
66 | + if ($tokens[ $index ][ 'type' ] == 'T_INLINE_ELSE') { |
|
67 | 67 | $semiColinFound = true; |
68 | 68 | } |
69 | 69 | $index++; |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\ControlStructures; |
4 | 4 | |
@@ -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 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\ControlStructures; |
4 | 4 | |
@@ -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 | /** |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\Syntax; |
4 | 4 | |
@@ -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,21 +27,21 @@ 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 | $nextCodeLine = 0; |
36 | 36 | |
37 | - for ($index=$endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
|
38 | - if (isset($tokens[$index]) && $tokens[$index]['type'] !== 'T_WHITESPACE') { |
|
39 | - $nextCodeLine = $tokens[$index]['line']; |
|
37 | + for ($index = $endOfMethodIndex + 1; $index <= count($tokens); $index++) { |
|
38 | + if (isset($tokens[ $index ]) && $tokens[ $index ][ 'type' ] !== 'T_WHITESPACE') { |
|
39 | + $nextCodeLine = $tokens[ $index ][ 'line' ]; |
|
40 | 40 | break; |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - $linesBetween = $nextCodeLine - $tokens[$endOfMethodIndex]['line'] - 1; |
|
44 | + $linesBetween = $nextCodeLine - $tokens[ $endOfMethodIndex ][ 'line' ] - 1; |
|
45 | 45 | if ($linesBetween > 1) { |
46 | 46 | $phpcsFile->addError("No more than 1 line after a method/function is allowed.", $stackPtr, __CLASS__); |
47 | 47 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\Files; |
4 | 4 | |
@@ -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,14 +30,14 @@ 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 | $comparisonIndex = key($semicolons) - 3; |
39 | 39 | |
40 | - if ($scope[$returnValueIndex]['type'] === 'T_NULL' && $this->isComparisonType($scope[$comparisonIndex]['type']) === false) { |
|
40 | + if ($scope[ $returnValueIndex ][ 'type' ] === 'T_NULL' && $this->isComparisonType($scope[ $comparisonIndex ][ 'type' ]) === false) { |
|
41 | 41 | $error = "Return null value found."; |
42 | 42 | $phpcsFile->addError($error, $returnValueIndex, __CLASS__); |
43 | 43 | } |
@@ -45,6 +45,6 @@ discard block |
||
45 | 45 | |
46 | 46 | private function isComparisonType(string $type) : bool |
47 | 47 | { |
48 | - return in_array($type, ['T_IS_NOT_IDENTICAL', 'T_IS_IDENTICAL', 'T_IS_NOT_EQUAL', 'T_IS_EQUAL'], true); |
|
48 | + return in_array($type, [ 'T_IS_NOT_IDENTICAL', 'T_IS_IDENTICAL', 'T_IS_NOT_EQUAL', 'T_IS_EQUAL' ], true); |
|
49 | 49 | } |
50 | 50 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\Classes; |
4 | 4 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public function register(): array |
15 | 15 | { |
16 | - return [T_FUNCTION]; |
|
16 | + return [ T_FUNCTION ]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -27,25 +27,25 @@ discard block |
||
27 | 27 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
28 | 28 | { |
29 | 29 | $tokens = $phpcsFile->getTokens(); |
30 | - $functionName = $tokens[$stackPtr + 2]['content']; |
|
30 | + $functionName = $tokens[ $stackPtr + 2 ][ 'content' ]; |
|
31 | 31 | |
32 | 32 | $scopes = $this->getBracketsIndex($tokens, $stackPtr); |
33 | - if (true === empty($scopes['open']) || true === empty($scopes['close'])) { |
|
33 | + if (true === empty($scopes[ 'open' ]) || true === empty($scopes[ 'close' ])) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - for ($index=$scopes['open']; $index <= $scopes['close']; $index++) { |
|
38 | - if ($tokens[$index]['type'] === 'T_NEW') { |
|
39 | - $phpcsFile->addWarning($this->getWarningMessage($functionName), $tokens[$index]['column'], __CLASS__); |
|
37 | + for ($index = $scopes[ 'open' ]; $index <= $scopes[ 'close' ]; $index++) { |
|
38 | + if ($tokens[ $index ][ 'type' ] === 'T_NEW') { |
|
39 | + $phpcsFile->addWarning($this->getWarningMessage($functionName), $tokens[ $index ][ 'column' ], __CLASS__); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | private function getBracketsIndex(array $tokens, int $stackPtr) : array |
45 | 45 | { |
46 | - $token = $tokens[$stackPtr]; |
|
47 | - $open = $token['scope_opener'] ?? null; |
|
48 | - $close = $token['scope_closer'] ?? null; |
|
46 | + $token = $tokens[ $stackPtr ]; |
|
47 | + $open = $token[ 'scope_opener' ] ?? null; |
|
48 | + $close = $token[ 'scope_closer' ] ?? null; |
|
49 | 49 | |
50 | 50 | if (true === empty($open)) { |
51 | 51 | return $this->searchBrackets($tokens, $stackPtr); |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | private function searchBrackets(array $tokens, int $stackPtr) : array |
61 | 61 | { |
62 | 62 | $open = $close = null; |
63 | - for ($i=$stackPtr; $i < count($tokens); $i++) { |
|
64 | - if ($tokens[$i]['type'] === 'T_OPEN_CURLY_BRACKET') { |
|
63 | + for ($i = $stackPtr; $i < count($tokens); $i++) { |
|
64 | + if ($tokens[ $i ][ 'type' ] === 'T_OPEN_CURLY_BRACKET') { |
|
65 | 65 | $open = $i; |
66 | 66 | } |
67 | - if ($tokens[$i]['type'] === 'T_CLOSE_CURLY_BRACKET') { |
|
67 | + if ($tokens[ $i ][ 'type' ] === 'T_CLOSE_CURLY_BRACKET') { |
|
68 | 68 | $close = $i; |
69 | 69 | } |
70 | 70 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types = 1); |
|
1 | +<?php declare(strict_types=1); |
|
2 | 2 | |
3 | 3 | namespace Codor\Sniffs\Classes; |
4 | 4 | |
@@ -12,19 +12,19 @@ discard block |
||
12 | 12 | * The decalred member variables in the class. |
13 | 13 | * @var array |
14 | 14 | */ |
15 | - protected $memberVars = []; |
|
15 | + protected $memberVars = [ ]; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * The referenced member variables in the class. |
19 | 19 | * @var array |
20 | 20 | */ |
21 | - protected $referencedMemberVars = []; |
|
21 | + protected $referencedMemberVars = [ ]; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Visibility Tokens. |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $visibilityTokens = ['T_PRIVATE', 'T_PUBLIC', 'T_PROTECTED']; |
|
27 | + protected $visibilityTokens = [ 'T_PRIVATE', 'T_PUBLIC', 'T_PROTECTED' ]; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Holds the value if the class is extended or not. |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register(): array |
40 | 40 | { |
41 | - return [T_CLASS]; |
|
41 | + return [ T_CLASS ]; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
54 | 54 | { |
55 | - $this->memberVars = []; |
|
56 | - $this->referencedMemberVars = []; |
|
55 | + $this->memberVars = [ ]; |
|
56 | + $this->referencedMemberVars = [ ]; |
|
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | foreach ($tokens as $index => $token) { |
59 | 59 | $this->handleToken($tokens, $index); |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function handleToken($tokens, $index) |
76 | 76 | { |
77 | - $token = $tokens[$index]; |
|
77 | + $token = $tokens[ $index ]; |
|
78 | 78 | |
79 | - if ($token['type'] === 'T_EXTENDS') { |
|
79 | + if ($token[ 'type' ] === 'T_EXTENDS') { |
|
80 | 80 | $this->isExtendedClass = true; |
81 | 81 | return; |
82 | 82 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | |
90 | - if ($token['type'] === 'T_OBJECT_OPERATOR') { |
|
90 | + if ($token[ 'type' ] === 'T_OBJECT_OPERATOR') { |
|
91 | 91 | $this->handleObjectOperatorToken($tokens, $index); |
92 | 92 | return; |
93 | 93 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function isVisibilityToken($token): bool |
102 | 102 | { |
103 | - return in_array($token['type'], $this->visibilityTokens); |
|
103 | + return in_array($token[ 'type' ], $this->visibilityTokens); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | $count = count($tokens); |
115 | 115 | |
116 | 116 | for ($i = $index + 1; $i < $count; $i++) { |
117 | - $possibleVariable = $tokens[$i]; |
|
117 | + $possibleVariable = $tokens[ $i ]; |
|
118 | 118 | |
119 | - if ($possibleVariable['type'] === 'T_CONST' |
|
120 | - || $possibleVariable['type'] === 'T_FUNCTION' |
|
121 | - || $possibleVariable['type'] === 'T_SEMICOLON' |
|
119 | + if ($possibleVariable[ 'type' ] === 'T_CONST' |
|
120 | + || $possibleVariable[ 'type' ] === 'T_FUNCTION' |
|
121 | + || $possibleVariable[ 'type' ] === 'T_SEMICOLON' |
|
122 | 122 | ) { |
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | - if ($possibleVariable['type'] !== 'T_VARIABLE') { |
|
126 | + if ($possibleVariable[ 'type' ] !== 'T_VARIABLE') { |
|
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | |
130 | - $this->memberVars[] = str_replace('$', '', $possibleVariable['content']); |
|
130 | + $this->memberVars[ ] = str_replace('$', '', $possibleVariable[ 'content' ]); |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | } |
@@ -140,19 +140,19 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function handleObjectOperatorToken($tokens, $index) |
142 | 142 | { |
143 | - $previousToken = $tokens[$index-1]; |
|
144 | - $nextToken = $tokens[$index+1]; |
|
145 | - $tokenAfterNext = $tokens[$index+2]; |
|
143 | + $previousToken = $tokens[ $index - 1 ]; |
|
144 | + $nextToken = $tokens[ $index + 1 ]; |
|
145 | + $tokenAfterNext = $tokens[ $index + 2 ]; |
|
146 | 146 | |
147 | - if ($previousToken['content'] !== '$this') { |
|
147 | + if ($previousToken[ 'content' ] !== '$this') { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | - if (($tokenAfterNext['type'] !== 'T_WHITESPACE') && ($tokenAfterNext['type'] !== 'T_EQUAL')) { |
|
151 | + if (($tokenAfterNext[ 'type' ] !== 'T_WHITESPACE') && ($tokenAfterNext[ 'type' ] !== 'T_EQUAL')) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | |
155 | - $this->referencedMemberVars[] = $nextToken['content']; |
|
155 | + $this->referencedMemberVars[ ] = $nextToken[ 'content' ]; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |