@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | + public function process( File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | - if ($this->supportsBelow('7.3') === false) { |
|
53 | + if ( $this->supportsBelow( '7.3' ) === false ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
@@ -60,38 +60,38 @@ discard block |
||
60 | 60 | * Determine the array opener & closer. |
61 | 61 | */ |
62 | 62 | $closer = $phpcsFile->numTokens; |
63 | - if ($tokens[$stackPtr]['code'] === \T_ARRAY) { |
|
64 | - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) { |
|
63 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_ARRAY ) { |
|
64 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ] ) === false ) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
68 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
69 | 69 | |
70 | - if (isset($tokens[$opener]['parenthesis_closer'])) { |
|
71 | - $closer = $tokens[$opener]['parenthesis_closer']; |
|
70 | + if ( isset( $tokens[ $opener ][ 'parenthesis_closer' ] ) ) { |
|
71 | + $closer = $tokens[ $opener ][ 'parenthesis_closer' ]; |
|
72 | 72 | } |
73 | 73 | } else { |
74 | 74 | // Short array syntax. |
75 | 75 | $opener = $stackPtr; |
76 | 76 | |
77 | - if (isset($tokens[$stackPtr]['bracket_closer'])) { |
|
78 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
77 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
78 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | $nestingLevel = 0; |
83 | - if (isset($tokens[($opener + 1)]['nested_parenthesis'])) { |
|
84 | - $nestingLevel = count($tokens[($opener + 1)]['nested_parenthesis']); |
|
83 | + if ( isset( $tokens[ ( $opener + 1 ) ][ 'nested_parenthesis' ] ) ) { |
|
84 | + $nestingLevel = count( $tokens[ ( $opener + 1 ) ][ 'nested_parenthesis' ] ); |
|
85 | 85 | } |
86 | 86 | |
87 | - for ($i = $opener; $i < $closer;) { |
|
88 | - $i = $phpcsFile->findNext(array(\T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY), ($i + 1), $closer); |
|
89 | - if ($i === false) { |
|
87 | + for ( $i = $opener; $i < $closer; ) { |
|
88 | + $i = $phpcsFile->findNext( array( \T_ELLIPSIS, \T_OPEN_SHORT_ARRAY, \T_ARRAY ), ( $i + 1 ), $closer ); |
|
89 | + if ( $i === false ) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | - if ($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
94 | - if (isset($tokens[$i]['bracket_closer']) === false) { |
|
93 | + if ( $tokens[ $i ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) { |
|
94 | + if ( isset( $tokens[ $i ][ 'bracket_closer' ] ) === false ) { |
|
95 | 95 | // Live coding, unfinished nested array, handle this when the array opener |
96 | 96 | // of the nested array is passed. |
97 | 97 | return; |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | |
100 | 100 | // Skip over nested short arrays. These will be handled when the array opener |
101 | 101 | // of the nested array is passed. |
102 | - $i = $tokens[$i]['bracket_closer']; |
|
102 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - if ($tokens[$i]['code'] === \T_ARRAY) { |
|
107 | - if (isset($tokens[$i]['parenthesis_closer']) === false) { |
|
106 | + if ( $tokens[ $i ][ 'code' ] === \T_ARRAY ) { |
|
107 | + if ( isset( $tokens[ $i ][ 'parenthesis_closer' ] ) === false ) { |
|
108 | 108 | // Live coding, unfinished nested array, handle this when the array opener |
109 | 109 | // of the nested array is passed. |
110 | 110 | return; |
@@ -112,25 +112,25 @@ discard block |
||
112 | 112 | |
113 | 113 | // Skip over nested long arrays. These will be handled when the array opener |
114 | 114 | // of the nested array is passed. |
115 | - $i = $tokens[$i]['parenthesis_closer']; |
|
115 | + $i = $tokens[ $i ][ 'parenthesis_closer' ]; |
|
116 | 116 | continue; |
117 | 117 | } |
118 | 118 | |
119 | 119 | // Ensure this is not function call variable unpacking. |
120 | - if (isset($tokens[$i]['nested_parenthesis']) |
|
121 | - && count($tokens[$i]['nested_parenthesis']) > $nestingLevel |
|
120 | + if ( isset( $tokens[ $i ][ 'nested_parenthesis' ] ) |
|
121 | + && count( $tokens[ $i ][ 'nested_parenthesis' ] ) > $nestingLevel |
|
122 | 122 | ) { |
123 | 123 | continue; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Ok, found one. |
127 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
128 | - $snippet = trim($phpcsFile->getTokensAsString($i, (($nextNonEmpty - $i) + 1))); |
|
127 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
|
128 | + $snippet = trim( $phpcsFile->getTokensAsString( $i, ( ( $nextNonEmpty - $i ) + 1 ) ) ); |
|
129 | 129 | $phpcsFile->addError( |
130 | 130 | 'Array unpacking within array declarations using the spread operator is not supported in PHP 7.3 or earlier. Found: %s', |
131 | 131 | $i, |
132 | 132 | 'Found', |
133 | - array($snippet) |
|
133 | + array( $snippet ) |
|
134 | 134 | ); |
135 | 135 | } |
136 | 136 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(\T_INLINE_THEN); |
|
41 | + return array( \T_INLINE_THEN ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return void |
52 | 52 | */ |
53 | - public function process(File $phpcsFile, $stackPtr) |
|
53 | + public function process( File $phpcsFile, $stackPtr ) |
|
54 | 54 | { |
55 | - if ($this->supportsBelow('5.2') === false) { |
|
55 | + if ( $this->supportsBelow( '5.2' ) === false ) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | - if ($this->isShortTernary($phpcsFile, $stackPtr) === false) { |
|
59 | + if ( $this->isShortTernary( $phpcsFile, $stackPtr ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 |
@@ -80,105 +80,105 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return void |
82 | 82 | */ |
83 | - public function process(File $phpcsFile, $stackPtr) |
|
83 | + public function process( File $phpcsFile, $stackPtr ) |
|
84 | 84 | { |
85 | - if ($this->supportsAbove('7.4') === false) { |
|
85 | + if ( $this->supportsAbove( '7.4' ) === false ) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | - if ($this->isUnaryPlusMinus($phpcsFile, $stackPtr) === true) { |
|
89 | + if ( $this->isUnaryPlusMinus( $phpcsFile, $stackPtr ) === true ) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $tokens = $phpcsFile->getTokens(); |
94 | 94 | |
95 | - for ($i = ($stackPtr - 1); $stackPtr >= 0; $i--) { |
|
96 | - if ($tokens[$i]['code'] === \T_STRING_CONCAT) { |
|
95 | + for ( $i = ( $stackPtr - 1 ); $stackPtr >= 0; $i-- ) { |
|
96 | + if ( $tokens[ $i ][ 'code' ] === \T_STRING_CONCAT ) { |
|
97 | 97 | // Found one. |
98 | 98 | break; |
99 | 99 | } |
100 | 100 | |
101 | - if ($tokens[$i]['code'] === \T_SEMICOLON |
|
102 | - || $tokens[$i]['code'] === \T_OPEN_CURLY_BRACKET |
|
103 | - || $tokens[$i]['code'] === \T_OPEN_TAG |
|
104 | - || $tokens[$i]['code'] === \T_OPEN_TAG_WITH_ECHO |
|
105 | - || $tokens[$i]['code'] === \T_COMMA |
|
106 | - || $tokens[$i]['code'] === \T_COLON |
|
107 | - || $tokens[$i]['code'] === \T_CASE |
|
101 | + if ( $tokens[ $i ][ 'code' ] === \T_SEMICOLON |
|
102 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_CURLY_BRACKET |
|
103 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_TAG |
|
104 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_TAG_WITH_ECHO |
|
105 | + || $tokens[ $i ][ 'code' ] === \T_COMMA |
|
106 | + || $tokens[ $i ][ 'code' ] === \T_COLON |
|
107 | + || $tokens[ $i ][ 'code' ] === \T_CASE |
|
108 | 108 | ) { |
109 | 109 | // If we reached any of the above tokens, we've reached the end of |
110 | 110 | // the statement without encountering a concatenation operator. |
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - if ($tokens[$i]['code'] === \T_OPEN_CURLY_BRACKET |
|
115 | - && isset($tokens[$i]['bracket_closer']) |
|
116 | - && $tokens[$i]['bracket_closer'] > $stackPtr |
|
114 | + if ( $tokens[ $i ][ 'code' ] === \T_OPEN_CURLY_BRACKET |
|
115 | + && isset( $tokens[ $i ][ 'bracket_closer' ] ) |
|
116 | + && $tokens[ $i ][ 'bracket_closer' ] > $stackPtr |
|
117 | 117 | ) { |
118 | 118 | // No need to look any further, this is plus/minus within curly braces |
119 | 119 | // and we've reached the open curly. |
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - if ($tokens[$i]['code'] === \T_OPEN_PARENTHESIS |
|
124 | - && isset($tokens[$i]['parenthesis_closer']) |
|
125 | - && $tokens[$i]['parenthesis_closer'] > $stackPtr |
|
123 | + if ( $tokens[ $i ][ 'code' ] === \T_OPEN_PARENTHESIS |
|
124 | + && isset( $tokens[ $i ][ 'parenthesis_closer' ] ) |
|
125 | + && $tokens[ $i ][ 'parenthesis_closer' ] > $stackPtr |
|
126 | 126 | ) { |
127 | 127 | // No need to look any further, this is plus/minus within parenthesis |
128 | 128 | // and we've reached the open parenthesis. |
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - if (($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY |
|
133 | - || $tokens[$i]['code'] === \T_OPEN_SQUARE_BRACKET) |
|
134 | - && isset($tokens[$i]['bracket_closer']) |
|
135 | - && $tokens[$i]['bracket_closer'] > $stackPtr |
|
132 | + if ( ( $tokens[ $i ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
133 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_SQUARE_BRACKET ) |
|
134 | + && isset( $tokens[ $i ][ 'bracket_closer' ] ) |
|
135 | + && $tokens[ $i ][ 'bracket_closer' ] > $stackPtr |
|
136 | 136 | ) { |
137 | 137 | // No need to look any further, this is plus/minus within a short array |
138 | 138 | // or array key square brackets and we've reached the opener. |
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - if ($tokens[$i]['code'] === \T_CLOSE_CURLY_BRACKET) { |
|
143 | - if (isset($tokens[$i]['scope_owner'])) { |
|
142 | + if ( $tokens[ $i ][ 'code' ] === \T_CLOSE_CURLY_BRACKET ) { |
|
143 | + if ( isset( $tokens[ $i ][ 'scope_owner' ] ) ) { |
|
144 | 144 | // Different scope, we've passed the start of the statement. |
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | - if (isset($tokens[$i]['bracket_opener'])) { |
|
149 | - $i = $tokens[$i]['bracket_opener']; |
|
148 | + if ( isset( $tokens[ $i ][ 'bracket_opener' ] ) ) { |
|
149 | + $i = $tokens[ $i ][ 'bracket_opener' ]; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | - if ($tokens[$i]['code'] === \T_CLOSE_PARENTHESIS |
|
156 | - && isset($tokens[$i]['parenthesis_opener']) |
|
155 | + if ( $tokens[ $i ][ 'code' ] === \T_CLOSE_PARENTHESIS |
|
156 | + && isset( $tokens[ $i ][ 'parenthesis_opener' ] ) |
|
157 | 157 | ) { |
158 | 158 | // Skip over statements in parenthesis, including long arrays. |
159 | - $i = $tokens[$i]['parenthesis_opener']; |
|
159 | + $i = $tokens[ $i ][ 'parenthesis_opener' ]; |
|
160 | 160 | continue; |
161 | 161 | } |
162 | 162 | |
163 | - if (($tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET |
|
164 | - || $tokens[$i]['code'] === \T_CLOSE_SHORT_ARRAY) |
|
165 | - && isset($tokens[$i]['bracket_opener']) |
|
163 | + if ( ( $tokens[ $i ][ 'code' ] === \T_CLOSE_SQUARE_BRACKET |
|
164 | + || $tokens[ $i ][ 'code' ] === \T_CLOSE_SHORT_ARRAY ) |
|
165 | + && isset( $tokens[ $i ][ 'bracket_opener' ] ) |
|
166 | 166 | ) { |
167 | 167 | // Skip over array keys and short arrays. |
168 | - $i = $tokens[$i]['bracket_opener']; |
|
168 | + $i = $tokens[ $i ][ 'bracket_opener' ]; |
|
169 | 169 | continue; |
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check for chain being broken by a token with a lower precedence. |
173 | - if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true |
|
174 | - || isset(Tokens::$assignmentTokens[$tokens[$i]['code']]) === true |
|
173 | + if ( isset( Tokens::$booleanOperators[ $tokens[ $i ][ 'code' ] ] ) === true |
|
174 | + || isset( Tokens::$assignmentTokens[ $tokens[ $i ][ 'code' ] ] ) === true |
|
175 | 175 | ) { |
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - if (isset($this->tokensWithLowerPrecedence[$tokens[$i]['type']]) === true) { |
|
180 | - if ($tokens[$i]['code'] === \T_BITWISE_AND |
|
181 | - && $phpcsFile->isReference($i) === true |
|
179 | + if ( isset( $this->tokensWithLowerPrecedence[ $tokens[ $i ][ 'type' ] ] ) === true ) { |
|
180 | + if ( $tokens[ $i ][ 'code' ] === \T_BITWISE_AND |
|
181 | + && $phpcsFile->isReference( $i ) === true |
|
182 | 182 | ) { |
183 | 183 | continue; |
184 | 184 | } |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | |
190 | 190 | $message = 'Using an unparenthesized expression containing a "." before a "+" or "-" has been deprecated in PHP 7.4'; |
191 | 191 | $isError = false; |
192 | - if ($this->supportsAbove('8.0') === true) { |
|
192 | + if ( $this->supportsAbove( '8.0' ) === true ) { |
|
193 | 193 | $message .= ' and removed in PHP 8.0'; |
194 | 194 | $isError = true; |
195 | 195 | } |
196 | 196 | |
197 | - $this->addMessage($phpcsFile, $message, $i, $isError); |
|
197 | + $this->addMessage( $phpcsFile, $message, $i, $isError ); |
|
198 | 198 | } |
199 | 199 | } |
@@ -69,27 +69,27 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function process(File $phpcsFile, $stackPtr) |
|
72 | + public function process( File $phpcsFile, $stackPtr ) |
|
73 | 73 | { |
74 | - if ($this->supportsAbove('7.0') === false) { |
|
74 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $tokens = $phpcsFile->getTokens(); |
79 | 79 | |
80 | 80 | // Determine the start and end of the part of the statement we need to examine. |
81 | - $start = ($stackPtr + 1); |
|
82 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, $start, null, true); |
|
83 | - if ($next !== false && $tokens[$next]['code'] === \T_OPEN_PARENTHESIS) { |
|
84 | - $start = ($next + 1); |
|
81 | + $start = ( $stackPtr + 1 ); |
|
82 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, $start, null, true ); |
|
83 | + if ( $next !== false && $tokens[ $next ][ 'code' ] === \T_OPEN_PARENTHESIS ) { |
|
84 | + $start = ( $next + 1 ); |
|
85 | 85 | } |
86 | 86 | |
87 | - $end = PHPCSHelper::findEndOfStatement($phpcsFile, $start); |
|
88 | - if (isset($this->inclusiveStopPoints[$tokens[$end]['code']]) === true) { |
|
87 | + $end = PHPCSHelper::findEndOfStatement( $phpcsFile, $start ); |
|
88 | + if ( isset( $this->inclusiveStopPoints[ $tokens[ $end ][ 'code' ] ] ) === true ) { |
|
89 | 89 | --$end; |
90 | 90 | } |
91 | 91 | |
92 | - if ($this->isNegativeNumber($phpcsFile, $start, $end, true) !== true) { |
|
92 | + if ( $this->isNegativeNumber( $phpcsFile, $start, $end, true ) !== true ) { |
|
93 | 93 | // Not a negative number or undetermined. |
94 | 94 | return; |
95 | 95 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | 'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0. Found: %s', |
99 | 99 | $stackPtr, |
100 | 100 | 'Found', |
101 | - array($phpcsFile->getTokensAsString($start, ($end - $start + 1))) |
|
101 | + array( $phpcsFile->getTokensAsString( $start, ( $end - $start + 1 ) ) ) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function register() |
57 | 57 | { |
58 | - return array(\T_INLINE_THEN); |
|
58 | + return array( \T_INLINE_THEN ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -69,20 +69,20 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function process(File $phpcsFile, $stackPtr) |
|
72 | + public function process( File $phpcsFile, $stackPtr ) |
|
73 | 73 | { |
74 | - if ($this->supportsAbove('7.4') === false) { |
|
74 | + if ( $this->supportsAbove( '7.4' ) === false ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $tokens = $phpcsFile->getTokens(); |
79 | - $endOfStatement = PHPCSHelper::findEndOfStatement($phpcsFile, $stackPtr); |
|
80 | - if ($tokens[$endOfStatement]['code'] !== \T_SEMICOLON |
|
81 | - && $tokens[$endOfStatement]['code'] !== \T_COLON |
|
82 | - && $tokens[$endOfStatement]['code'] !== \T_COMMA |
|
83 | - && $tokens[$endOfStatement]['code'] !== \T_DOUBLE_ARROW |
|
84 | - && $tokens[$endOfStatement]['code'] !== \T_OPEN_TAG |
|
85 | - && $tokens[$endOfStatement]['code'] !== \T_CLOSE_TAG |
|
79 | + $endOfStatement = PHPCSHelper::findEndOfStatement( $phpcsFile, $stackPtr ); |
|
80 | + if ( $tokens[ $endOfStatement ][ 'code' ] !== \T_SEMICOLON |
|
81 | + && $tokens[ $endOfStatement ][ 'code' ] !== \T_COLON |
|
82 | + && $tokens[ $endOfStatement ][ 'code' ] !== \T_COMMA |
|
83 | + && $tokens[ $endOfStatement ][ 'code' ] !== \T_DOUBLE_ARROW |
|
84 | + && $tokens[ $endOfStatement ][ 'code' ] !== \T_OPEN_TAG |
|
85 | + && $tokens[ $endOfStatement ][ 'code' ] !== \T_CLOSE_TAG |
|
86 | 86 | ) { |
87 | 87 | // End of statement is last non-empty before close brace, so make sure we examine that token too. |
88 | 88 | ++$endOfStatement; |
@@ -93,44 +93,44 @@ discard block |
||
93 | 93 | $shortTernaryCount = 0; |
94 | 94 | |
95 | 95 | // Start at $stackPtr so we don't need duplicate code for short ternary determination. |
96 | - for ($i = $stackPtr; $i < $endOfStatement; $i++) { |
|
97 | - if (($tokens[$i]['code'] === \T_OPEN_SHORT_ARRAY |
|
98 | - || $tokens[$i]['code'] === \T_OPEN_SQUARE_BRACKET |
|
99 | - || $tokens[$i]['code'] === \T_OPEN_CURLY_BRACKET) |
|
100 | - && isset($tokens[$i]['bracket_closer']) |
|
96 | + for ( $i = $stackPtr; $i < $endOfStatement; $i++ ) { |
|
97 | + if ( ( $tokens[ $i ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
98 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_SQUARE_BRACKET |
|
99 | + || $tokens[ $i ][ 'code' ] === \T_OPEN_CURLY_BRACKET ) |
|
100 | + && isset( $tokens[ $i ][ 'bracket_closer' ] ) |
|
101 | 101 | ) { |
102 | 102 | // Skip over short arrays, array access keys and curlies. |
103 | - $i = $tokens[$i]['bracket_closer']; |
|
103 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | |
107 | - if ($tokens[$i]['code'] === \T_OPEN_PARENTHESIS |
|
108 | - && isset($tokens[$i]['parenthesis_closer']) |
|
107 | + if ( $tokens[ $i ][ 'code' ] === \T_OPEN_PARENTHESIS |
|
108 | + && isset( $tokens[ $i ][ 'parenthesis_closer' ] ) |
|
109 | 109 | ) { |
110 | 110 | // Skip over anything between parentheses. |
111 | - $i = $tokens[$i]['parenthesis_closer']; |
|
111 | + $i = $tokens[ $i ][ 'parenthesis_closer' ]; |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
115 | 115 | // Check for operators with lower operator precedence. |
116 | - if (isset(Tokens::$assignmentTokens[$tokens[$i]['code']]) |
|
117 | - || isset($this->tokensWithLowerPrecedence[$tokens[$i]['code']]) |
|
116 | + if ( isset( Tokens::$assignmentTokens[ $tokens[ $i ][ 'code' ] ] ) |
|
117 | + || isset( $this->tokensWithLowerPrecedence[ $tokens[ $i ][ 'code' ] ] ) |
|
118 | 118 | ) { |
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - if ($tokens[$i]['code'] === \T_INLINE_THEN) { |
|
122 | + if ( $tokens[ $i ][ 'code' ] === \T_INLINE_THEN ) { |
|
123 | 123 | ++$ternaryCount; |
124 | 124 | |
125 | - if ($this->isShortTernary($phpcsFile, $i) === true) { |
|
125 | + if ( $this->isShortTernary( $phpcsFile, $i ) === true ) { |
|
126 | 126 | ++$shortTernaryCount; |
127 | 127 | } |
128 | 128 | |
129 | 129 | continue; |
130 | 130 | } |
131 | 131 | |
132 | - if ($tokens[$i]['code'] === \T_INLINE_ELSE) { |
|
133 | - if (($ternaryCount - $elseCount) >= 2) { |
|
132 | + if ( $tokens[ $i ][ 'code' ] === \T_INLINE_ELSE ) { |
|
133 | + if ( ( $ternaryCount - $elseCount ) >= 2 ) { |
|
134 | 134 | // This is the `else` for a ternary in the middle part of a previous ternary. |
135 | 135 | --$ternaryCount; |
136 | 136 | } else { |
@@ -140,17 +140,17 @@ discard block |
||
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - if ($ternaryCount > 1 && $ternaryCount === $elseCount && $ternaryCount > $shortTernaryCount) { |
|
143 | + if ( $ternaryCount > 1 && $ternaryCount === $elseCount && $ternaryCount > $shortTernaryCount ) { |
|
144 | 144 | $message = 'The left-associativity of the ternary operator has been deprecated in PHP 7.4'; |
145 | 145 | $isError = false; |
146 | - if ($this->supportsAbove('8.0') === true) { |
|
146 | + if ( $this->supportsAbove( '8.0' ) === true ) { |
|
147 | 147 | $message .= ' and removed in PHP 8.0'; |
148 | 148 | $isError = true; |
149 | 149 | } |
150 | 150 | |
151 | 151 | $message .= '. Multiple consecutive ternaries detected. Use parenthesis to clarify the order in which the operations should be executed'; |
152 | 152 | |
153 | - $this->addMessage($phpcsFile, $message, $stackPtr, $isError); |
|
153 | + $this->addMessage( $phpcsFile, $message, $stackPtr, $isError ); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | public function register() |
129 | 129 | { |
130 | 130 | $tokens = array(); |
131 | - foreach ($this->newOperators as $token => $versions) { |
|
132 | - if (\defined($token)) { |
|
133 | - $tokens[] = constant($token); |
|
134 | - } elseif (isset($this->newOperatorsPHPCSCompat[$token])) { |
|
135 | - $tokens[] = $this->newOperatorsPHPCSCompat[$token]; |
|
131 | + foreach ( $this->newOperators as $token => $versions ) { |
|
132 | + if ( \defined( $token ) ) { |
|
133 | + $tokens[ ] = constant( $token ); |
|
134 | + } elseif ( isset( $this->newOperatorsPHPCSCompat[ $token ] ) ) { |
|
135 | + $tokens[ ] = $this->newOperatorsPHPCSCompat[ $token ]; |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | return $tokens; |
@@ -148,38 +148,38 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function process(File $phpcsFile, $stackPtr) |
|
151 | + public function process( File $phpcsFile, $stackPtr ) |
|
152 | 152 | { |
153 | 153 | $tokens = $phpcsFile->getTokens(); |
154 | - $tokenType = $tokens[$stackPtr]['type']; |
|
154 | + $tokenType = $tokens[ $stackPtr ][ 'type' ]; |
|
155 | 155 | |
156 | 156 | // Translate older PHPCS token combis for new operators to the actual operator. |
157 | - if (isset($this->newOperators[$tokenType]) === false) { |
|
158 | - if (isset($this->PHPCSCompatTranslate[$tokenType]) |
|
159 | - && ((isset($this->PHPCSCompatTranslate[$tokenType]['before'], $tokens[$stackPtr - 1]) === true |
|
160 | - && $tokens[$stackPtr - 1]['type'] === $this->PHPCSCompatTranslate[$tokenType]['before']) |
|
161 | - || (isset($this->PHPCSCompatTranslate[$tokenType]['callback']) === true |
|
162 | - && \call_user_func(array($this, $this->PHPCSCompatTranslate[$tokenType]['callback']), $tokens, $stackPtr) === true)) |
|
157 | + if ( isset( $this->newOperators[ $tokenType ] ) === false ) { |
|
158 | + if ( isset( $this->PHPCSCompatTranslate[ $tokenType ] ) |
|
159 | + && ( ( isset( $this->PHPCSCompatTranslate[ $tokenType ][ 'before' ], $tokens[ $stackPtr - 1 ] ) === true |
|
160 | + && $tokens[ $stackPtr - 1 ][ 'type' ] === $this->PHPCSCompatTranslate[ $tokenType ][ 'before' ] ) |
|
161 | + || ( isset( $this->PHPCSCompatTranslate[ $tokenType ][ 'callback' ] ) === true |
|
162 | + && \call_user_func( array( $this, $this->PHPCSCompatTranslate[ $tokenType ][ 'callback' ] ), $tokens, $stackPtr ) === true ) ) |
|
163 | 163 | ) { |
164 | - $tokenType = $this->PHPCSCompatTranslate[$tokenType]['real_token']; |
|
164 | + $tokenType = $this->PHPCSCompatTranslate[ $tokenType ][ 'real_token' ]; |
|
165 | 165 | } |
166 | - } elseif ($tokenType === 'T_COALESCE') { |
|
166 | + } elseif ( $tokenType === 'T_COALESCE' ) { |
|
167 | 167 | // Make sure that T_COALESCE is not confused with T_COALESCE_EQUAL. |
168 | - if (isset($tokens[($stackPtr + 1)]) !== false && $tokens[($stackPtr + 1)]['code'] === \T_EQUAL) { |
|
168 | + if ( isset( $tokens[ ( $stackPtr + 1 ) ] ) !== false && $tokens[ ( $stackPtr + 1 ) ][ 'code' ] === \T_EQUAL ) { |
|
169 | 169 | // Ignore as will be dealt with via the T_EQUAL token. |
170 | 170 | return; |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | 174 | // If the translation did not yield one of the tokens we are looking for, bow out. |
175 | - if (isset($this->newOperators[$tokenType]) === false) { |
|
175 | + if ( isset( $this->newOperators[ $tokenType ] ) === false ) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | 179 | $itemInfo = array( |
180 | 180 | 'name' => $tokenType, |
181 | 181 | ); |
182 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
182 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return array Version and other information about the item. |
192 | 192 | */ |
193 | - public function getItemArray(array $itemInfo) |
|
193 | + public function getItemArray( array $itemInfo ) |
|
194 | 194 | { |
195 | - return $this->newOperators[$itemInfo['name']]; |
|
195 | + return $this->newOperators[ $itemInfo[ 'name' ] ]; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | protected function getNonVersionArrayKeys() |
205 | 205 | { |
206 | - return array('description'); |
|
206 | + return array( 'description' ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array |
217 | 217 | */ |
218 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
218 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
219 | 219 | { |
220 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
221 | - $errorInfo['description'] = $itemArray['description']; |
|
220 | + $errorInfo = parent::getErrorInfo( $itemArray, $itemInfo ); |
|
221 | + $errorInfo[ 'description' ] = $itemArray[ 'description' ]; |
|
222 | 222 | |
223 | 223 | return $errorInfo; |
224 | 224 | } |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return array |
235 | 235 | */ |
236 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
236 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
237 | 237 | { |
238 | - $data[0] = $errorInfo['description']; |
|
238 | + $data[ 0 ] = $errorInfo[ 'description' ]; |
|
239 | 239 | return $data; |
240 | 240 | } |
241 | 241 | |
@@ -248,18 +248,18 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return bool |
250 | 250 | */ |
251 | - private function isTCoalesceEqual($tokens, $stackPtr) |
|
251 | + private function isTCoalesceEqual( $tokens, $stackPtr ) |
|
252 | 252 | { |
253 | - if ($tokens[$stackPtr]['code'] !== \T_EQUAL || isset($tokens[($stackPtr - 1)]) === false) { |
|
253 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_EQUAL || isset( $tokens[ ( $stackPtr - 1 ) ] ) === false ) { |
|
254 | 254 | // Function called for wrong token or token has no predecesor. |
255 | 255 | return false; |
256 | 256 | } |
257 | 257 | |
258 | - if ($tokens[($stackPtr - 1)]['type'] === 'T_COALESCE') { |
|
258 | + if ( $tokens[ ( $stackPtr - 1 ) ][ 'type' ] === 'T_COALESCE' ) { |
|
259 | 259 | return true; |
260 | 260 | } |
261 | - if ($tokens[($stackPtr - 1)]['type'] === 'T_INLINE_THEN' |
|
262 | - && (isset($tokens[($stackPtr - 2)]) && $tokens[($stackPtr - 2)]['type'] === 'T_INLINE_THEN') |
|
261 | + if ( $tokens[ ( $stackPtr - 1 ) ][ 'type' ] === 'T_INLINE_THEN' |
|
262 | + && ( isset( $tokens[ ( $stackPtr - 2 ) ] ) && $tokens[ ( $stackPtr - 2 ) ][ 'type' ] === 'T_INLINE_THEN' ) |
|
263 | 263 | ) { |
264 | 264 | return true; |
265 | 265 | } |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return bool |
277 | 277 | */ |
278 | - private function isTCoalesce($tokens, $stackPtr) |
|
278 | + private function isTCoalesce( $tokens, $stackPtr ) |
|
279 | 279 | { |
280 | - if ($tokens[$stackPtr]['code'] !== \T_INLINE_THEN || isset($tokens[($stackPtr - 1)]) === false) { |
|
280 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_INLINE_THEN || isset( $tokens[ ( $stackPtr - 1 ) ] ) === false ) { |
|
281 | 281 | // Function called for wrong token or token has no predecesor. |
282 | 282 | return false; |
283 | 283 | } |
284 | 284 | |
285 | - if ($tokens[($stackPtr - 1)]['code'] === \T_INLINE_THEN) { |
|
285 | + if ( $tokens[ ( $stackPtr - 1 ) ][ 'code' ] === \T_INLINE_THEN ) { |
|
286 | 286 | // Make sure not to confuse it with the T_COALESCE_EQUAL token. |
287 | - if (isset($tokens[($stackPtr + 1)]) === false || $tokens[($stackPtr + 1)]['code'] !== \T_EQUAL) { |
|
287 | + if ( isset( $tokens[ ( $stackPtr + 1 ) ] ) === false || $tokens[ ( $stackPtr + 1 ) ][ 'code' ] !== \T_EQUAL ) { |
|
288 | 288 | return true; |
289 | 289 | } |
290 | 290 | } |
@@ -86,25 +86,25 @@ discard block |
||
86 | 86 | * @return int|void Integer stack pointer to skip forward or void to continue |
87 | 87 | * normal file processing. |
88 | 88 | */ |
89 | - public function process(File $phpcsFile, $stackPtr) |
|
89 | + public function process( File $phpcsFile, $stackPtr ) |
|
90 | 90 | { |
91 | 91 | // Don't do anything if the warning has already been thrown or is not necessary. |
92 | - if ($this->examine === false) { |
|
93 | - return ($phpcsFile->numTokens + 1); |
|
92 | + if ( $this->examine === false ) { |
|
93 | + return ( $phpcsFile->numTokens + 1 ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $phpcsVersion = PHPCSHelper::getVersion(); |
97 | 97 | |
98 | 98 | // Don't do anything if the PHPCS version used is above the minimum recommended version. |
99 | - if (version_compare($phpcsVersion, $this->minRecommendedVersion, '>=')) { |
|
99 | + if ( version_compare( $phpcsVersion, $this->minRecommendedVersion, '>=' ) ) { |
|
100 | 100 | $this->examine = false; |
101 | - return ($phpcsFile->numTokens + 1); |
|
101 | + return ( $phpcsFile->numTokens + 1 ); |
|
102 | 102 | } |
103 | 103 | |
104 | - if (version_compare($phpcsVersion, $this->minSupportedVersion, '<')) { |
|
104 | + if ( version_compare( $phpcsVersion, $this->minSupportedVersion, '<' ) ) { |
|
105 | 105 | $isError = true; |
106 | 106 | $message = "IMPORTANT: Please be advised that the minimum PHP_CodeSniffer version the PHPCompatibility standard supports is %s. You are currently using PHP_CodeSniffer %s. Please upgrade your PHP_CodeSniffer installation. The recommended version of PHP_CodeSniffer for PHPCompatibility is %s or higher."; |
107 | - $errorCode = 'Unsupported_' . $this->stringToErrorCode($this->minSupportedVersion); |
|
107 | + $errorCode = 'Unsupported_' . $this->stringToErrorCode( $this->minSupportedVersion ); |
|
108 | 108 | $replacements = array( |
109 | 109 | $this->minSupportedVersion, |
110 | 110 | $phpcsVersion, |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | } else { |
115 | 115 | $isError = false; |
116 | 116 | $message = "IMPORTANT: Please be advised that for the most reliable PHPCompatibility results, PHP_CodeSniffer %s or higher should be used. Support for lower versions will be dropped in the foreseeable future. You are currently using PHP_CodeSniffer %s. Please upgrade your PHP_CodeSniffer installation to version %s or higher."; |
117 | - $errorCode = 'BelowRecommended_' . $this->stringToErrorCode($this->minRecommendedVersion); |
|
117 | + $errorCode = 'BelowRecommended_' . $this->stringToErrorCode( $this->minRecommendedVersion ); |
|
118 | 118 | $replacements = array( |
119 | 119 | $this->minRecommendedVersion, |
120 | 120 | $phpcsVersion, |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * If/when the upstream PR has been merged and the minimum supported/recommended version |
150 | 150 | * of PHPCompatibility would go beyond that, the below code should be adjusted.}} |
151 | 151 | */ |
152 | - $reportWidth = PHPCSHelper::getCommandLineData($phpcsFile, 'reportWidth'); |
|
153 | - $showSources = PHPCSHelper::getCommandLineData($phpcsFile, 'showSources'); |
|
154 | - if ($showSources === true && version_compare($phpcsVersion, '2.3.0', '>=')) { |
|
152 | + $reportWidth = PHPCSHelper::getCommandLineData( $phpcsFile, 'reportWidth' ); |
|
153 | + $showSources = PHPCSHelper::getCommandLineData( $phpcsFile, 'showSources' ); |
|
154 | + if ( $showSources === true && version_compare( $phpcsVersion, '2.3.0', '>=' ) ) { |
|
155 | 155 | $reportWidth += 6; |
156 | 156 | } |
157 | 157 | |
158 | - $messageWidth = ($reportWidth - 15); // 15 is length of " # | WARNING | ". |
|
159 | - $delimiterLine = str_repeat('-', ($messageWidth)); |
|
158 | + $messageWidth = ( $reportWidth - 15 ); // 15 is length of " # | WARNING | ". |
|
159 | + $delimiterLine = str_repeat( '-', ( $messageWidth ) ); |
|
160 | 160 | $disableNotice = 'To disable this notice, add --exclude=PHPCompatibility.Upgrade.LowPHPCS to your command or add <exclude name="PHPCompatibility.Upgrade.LowPHPCS.%s"/> to your custom ruleset. '; |
161 | 161 | $thankYou = 'Thank you for using PHPCompatibility!'; |
162 | 162 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $message .= ' ' . $delimiterLine; |
166 | 166 | $message .= ' ' . $thankYou; |
167 | 167 | |
168 | - $this->addMessage($phpcsFile, $message, 0, $isError, $errorCode, $replacements); |
|
168 | + $this->addMessage( $phpcsFile, $message, 0, $isError, $errorCode, $replacements ); |
|
169 | 169 | |
170 | 170 | $this->examine = false; |
171 | 171 | } |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function register() |
100 | 100 | { |
101 | - if (\defined('T_ANON_CLASS')) { |
|
102 | - $this->ooScopeTokens['T_ANON_CLASS'] = \T_ANON_CLASS; |
|
101 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
102 | + $this->ooScopeTokens[ 'T_ANON_CLASS' ] = \T_ANON_CLASS; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $this->skipOverScopes += $this->ooScopeTokens; |
@@ -125,22 +125,22 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return void |
127 | 127 | */ |
128 | - public function process(File $phpcsFile, $stackPtr) |
|
128 | + public function process( File $phpcsFile, $stackPtr ) |
|
129 | 129 | { |
130 | - if ($this->supportsAbove('7.1') === false) { |
|
130 | + if ( $this->supportsAbove( '7.1' ) === false ) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $tokens = $phpcsFile->getTokens(); |
135 | 135 | |
136 | - switch ($tokens[$stackPtr]['code']) { |
|
136 | + switch ( $tokens[ $stackPtr ][ 'code' ] ) { |
|
137 | 137 | case \T_FUNCTION: |
138 | - $this->isThisUsedAsParameter($phpcsFile, $stackPtr); |
|
139 | - $this->isThisUsedOutsideObjectContext($phpcsFile, $stackPtr); |
|
138 | + $this->isThisUsedAsParameter( $phpcsFile, $stackPtr ); |
|
139 | + $this->isThisUsedOutsideObjectContext( $phpcsFile, $stackPtr ); |
|
140 | 140 | break; |
141 | 141 | |
142 | 142 | case \T_CLOSURE: |
143 | - $this->isThisUsedAsParameter($phpcsFile, $stackPtr); |
|
143 | + $this->isThisUsedAsParameter( $phpcsFile, $stackPtr ); |
|
144 | 144 | break; |
145 | 145 | |
146 | 146 | case \T_GLOBAL: |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * This worked in PHP 7.0, though in PHP 5.x, it would throw a |
150 | 150 | * fatal "Cannot re-assign $this" error. |
151 | 151 | */ |
152 | - $endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr + 1)); |
|
153 | - if ($endOfStatement === false) { |
|
152 | + $endOfStatement = $phpcsFile->findNext( array( \T_SEMICOLON, \T_CLOSE_TAG ), ( $stackPtr + 1 ) ); |
|
153 | + if ( $endOfStatement === false ) { |
|
154 | 154 | // No semi-colon - live coding. |
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - for ($i = ($stackPtr + 1); $i < $endOfStatement; $i++) { |
|
159 | - if ($tokens[$i]['code'] !== \T_VARIABLE || $tokens[$i]['content'] !== '$this') { |
|
158 | + for ( $i = ( $stackPtr + 1 ); $i < $endOfStatement; $i++ ) { |
|
159 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE || $tokens[ $i ][ 'content' ] !== '$this' ) { |
|
160 | 160 | continue; |
161 | 161 | } |
162 | 162 | |
@@ -173,17 +173,17 @@ discard block |
||
173 | 173 | /* |
174 | 174 | * $this can no longer be used as a catch variable. |
175 | 175 | */ |
176 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
176 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | $varPtr = $phpcsFile->findNext( |
181 | 181 | \T_VARIABLE, |
182 | - ($tokens[$stackPtr]['parenthesis_opener'] + 1), |
|
183 | - $tokens[$stackPtr]['parenthesis_closer'] |
|
182 | + ( $tokens[ $stackPtr ][ 'parenthesis_opener' ] + 1 ), |
|
183 | + $tokens[ $stackPtr ][ 'parenthesis_closer' ] |
|
184 | 184 | ); |
185 | 185 | |
186 | - if ($varPtr === false || $tokens[$varPtr]['content'] !== '$this') { |
|
186 | + if ( $varPtr === false || $tokens[ $varPtr ][ 'content' ] !== '$this' ) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
@@ -201,38 +201,38 @@ discard block |
||
201 | 201 | * This worked in PHP 7.0, though in PHP 5.x, it would throw a |
202 | 202 | * fatal "Cannot re-assign $this" error. |
203 | 203 | */ |
204 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
204 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $stopPtr = $phpcsFile->findPrevious( |
209 | - array(\T_AS, \T_DOUBLE_ARROW), |
|
210 | - ($tokens[$stackPtr]['parenthesis_closer'] - 1), |
|
211 | - $tokens[$stackPtr]['parenthesis_opener'] |
|
209 | + array( \T_AS, \T_DOUBLE_ARROW ), |
|
210 | + ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] - 1 ), |
|
211 | + $tokens[ $stackPtr ][ 'parenthesis_opener' ] |
|
212 | 212 | ); |
213 | - if ($stopPtr === false) { |
|
213 | + if ( $stopPtr === false ) { |
|
214 | 214 | return; |
215 | 215 | } |
216 | 216 | |
217 | 217 | $valueVarPtr = $phpcsFile->findNext( |
218 | 218 | \T_VARIABLE, |
219 | - ($stopPtr + 1), |
|
220 | - $tokens[$stackPtr]['parenthesis_closer'] |
|
219 | + ( $stopPtr + 1 ), |
|
220 | + $tokens[ $stackPtr ][ 'parenthesis_closer' ] |
|
221 | 221 | ); |
222 | - if ($valueVarPtr === false || $tokens[$valueVarPtr]['content'] !== '$this') { |
|
222 | + if ( $valueVarPtr === false || $tokens[ $valueVarPtr ][ 'content' ] !== '$this' ) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
226 | 226 | $afterThis = $phpcsFile->findNext( |
227 | 227 | Tokens::$emptyTokens, |
228 | - ($valueVarPtr + 1), |
|
229 | - $tokens[$stackPtr]['parenthesis_closer'], |
|
228 | + ( $valueVarPtr + 1 ), |
|
229 | + $tokens[ $stackPtr ][ 'parenthesis_closer' ], |
|
230 | 230 | true |
231 | 231 | ); |
232 | 232 | |
233 | - if ($afterThis !== false |
|
234 | - && ($tokens[$afterThis]['code'] === \T_OBJECT_OPERATOR |
|
235 | - || $tokens[$afterThis]['code'] === \T_DOUBLE_COLON) |
|
233 | + if ( $afterThis !== false |
|
234 | + && ( $tokens[ $afterThis ][ 'code' ] === \T_OBJECT_OPERATOR |
|
235 | + || $tokens[ $afterThis ][ 'code' ] === \T_DOUBLE_COLON ) |
|
236 | 236 | ) { |
237 | 237 | return; |
238 | 238 | } |
@@ -249,30 +249,30 @@ discard block |
||
249 | 249 | /* |
250 | 250 | * $this can no longer be unset. |
251 | 251 | */ |
252 | - $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
253 | - if ($openParenthesis === false |
|
254 | - || $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS |
|
255 | - || isset($tokens[$openParenthesis]['parenthesis_closer']) === false |
|
252 | + $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
253 | + if ( $openParenthesis === false |
|
254 | + || $tokens[ $openParenthesis ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
255 | + || isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) === false |
|
256 | 256 | ) { |
257 | 257 | return; |
258 | 258 | } |
259 | 259 | |
260 | - for ($i = ($openParenthesis + 1); $i < $tokens[$openParenthesis]['parenthesis_closer']; $i++) { |
|
261 | - if ($tokens[$i]['code'] !== \T_VARIABLE || $tokens[$i]['content'] !== '$this') { |
|
260 | + for ( $i = ( $openParenthesis + 1 ); $i < $tokens[ $openParenthesis ][ 'parenthesis_closer' ]; $i++ ) { |
|
261 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE || $tokens[ $i ][ 'content' ] !== '$this' ) { |
|
262 | 262 | continue; |
263 | 263 | } |
264 | 264 | |
265 | 265 | $afterThis = $phpcsFile->findNext( |
266 | 266 | Tokens::$emptyTokens, |
267 | - ($i + 1), |
|
268 | - $tokens[$openParenthesis]['parenthesis_closer'], |
|
267 | + ( $i + 1 ), |
|
268 | + $tokens[ $openParenthesis ][ 'parenthesis_closer' ], |
|
269 | 269 | true |
270 | 270 | ); |
271 | 271 | |
272 | - if ($afterThis !== false |
|
273 | - && ($tokens[$afterThis]['code'] === \T_OBJECT_OPERATOR |
|
274 | - || $tokens[$afterThis]['code'] === \T_DOUBLE_COLON |
|
275 | - || $tokens[$afterThis]['code'] === \T_OPEN_SQUARE_BRACKET) |
|
272 | + if ( $afterThis !== false |
|
273 | + && ( $tokens[ $afterThis ][ 'code' ] === \T_OBJECT_OPERATOR |
|
274 | + || $tokens[ $afterThis ][ 'code' ] === \T_DOUBLE_COLON |
|
275 | + || $tokens[ $afterThis ][ 'code' ] === \T_OPEN_SQUARE_BRACKET ) |
|
276 | 276 | ) { |
277 | 277 | $i = $afterThis; |
278 | 278 | continue; |
@@ -303,34 +303,34 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return void |
305 | 305 | */ |
306 | - protected function isThisUsedAsParameter(File $phpcsFile, $stackPtr) |
|
306 | + protected function isThisUsedAsParameter( File $phpcsFile, $stackPtr ) |
|
307 | 307 | { |
308 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) !== false) { |
|
308 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) !== false ) { |
|
309 | 309 | return; |
310 | 310 | } |
311 | 311 | |
312 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
313 | - if (empty($params)) { |
|
312 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
313 | + if ( empty( $params ) ) { |
|
314 | 314 | return; |
315 | 315 | } |
316 | 316 | |
317 | 317 | $tokens = $phpcsFile->getTokens(); |
318 | 318 | |
319 | - foreach ($params as $param) { |
|
320 | - if ($param['name'] !== '$this') { |
|
319 | + foreach ( $params as $param ) { |
|
320 | + if ( $param[ 'name' ] !== '$this' ) { |
|
321 | 321 | continue; |
322 | 322 | } |
323 | 323 | |
324 | - if ($tokens[$stackPtr]['code'] === \T_FUNCTION) { |
|
324 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_FUNCTION ) { |
|
325 | 325 | $phpcsFile->addError( |
326 | 326 | '"$this" can no longer be used as a parameter since PHP 7.1.', |
327 | - $param['token'], |
|
327 | + $param[ 'token' ], |
|
328 | 328 | 'FunctionParam' |
329 | 329 | ); |
330 | 330 | } else { |
331 | 331 | $phpcsFile->addError( |
332 | 332 | '"$this" can no longer be used as a closure parameter since PHP 7.0.7.', |
333 | - $param['token'], |
|
333 | + $param[ 'token' ], |
|
334 | 334 | 'ClosureParam' |
335 | 335 | ); |
336 | 336 | } |
@@ -355,21 +355,21 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return void |
357 | 357 | */ |
358 | - protected function isThisUsedOutsideObjectContext(File $phpcsFile, $stackPtr) |
|
358 | + protected function isThisUsedOutsideObjectContext( File $phpcsFile, $stackPtr ) |
|
359 | 359 | { |
360 | 360 | $tokens = $phpcsFile->getTokens(); |
361 | 361 | |
362 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
362 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) !== false) { |
|
367 | - $methodProps = $phpcsFile->getMethodProperties($stackPtr); |
|
368 | - if ($methodProps['is_static'] === false) { |
|
366 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) !== false ) { |
|
367 | + $methodProps = $phpcsFile->getMethodProperties( $stackPtr ); |
|
368 | + if ( $methodProps[ 'is_static' ] === false ) { |
|
369 | 369 | return; |
370 | 370 | } else { |
371 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
372 | - if ($methodName === '__call') { |
|
371 | + $methodName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
372 | + if ( $methodName === '__call' ) { |
|
373 | 373 | /* |
374 | 374 | * This is an exception. |
375 | 375 | * @link https://wiki.php.net/rfc/this_var#always_show_true_this_value_in_magic_method_call |
@@ -379,37 +379,37 @@ discard block |
||
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - for ($i = ($tokens[$stackPtr]['scope_opener'] + 1); $i < $tokens[$stackPtr]['scope_closer']; $i++) { |
|
383 | - if (isset($this->skipOverScopes[$tokens[$i]['type']])) { |
|
384 | - if (isset($tokens[$i]['scope_closer']) === false) { |
|
382 | + for ( $i = ( $tokens[ $stackPtr ][ 'scope_opener' ] + 1 ); $i < $tokens[ $stackPtr ][ 'scope_closer' ]; $i++ ) { |
|
383 | + if ( isset( $this->skipOverScopes[ $tokens[ $i ][ 'type' ] ] ) ) { |
|
384 | + if ( isset( $tokens[ $i ][ 'scope_closer' ] ) === false ) { |
|
385 | 385 | // Live coding or parse error, will only lead to inaccurate results. |
386 | 386 | return; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // Skip over nested structures. |
390 | - $i = $tokens[$i]['scope_closer']; |
|
390 | + $i = $tokens[ $i ][ 'scope_closer' ]; |
|
391 | 391 | continue; |
392 | 392 | } |
393 | 393 | |
394 | - if ($tokens[$i]['code'] !== \T_VARIABLE || $tokens[$i]['content'] !== '$this') { |
|
394 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE || $tokens[ $i ][ 'content' ] !== '$this' ) { |
|
395 | 395 | continue; |
396 | 396 | } |
397 | 397 | |
398 | - if (isset($tokens[$i]['nested_parenthesis']) === true) { |
|
399 | - $nestedParenthesis = $tokens[$i]['nested_parenthesis']; |
|
400 | - $nestedOpenParenthesis = array_keys($nestedParenthesis); |
|
401 | - $lastOpenParenthesis = array_pop($nestedOpenParenthesis); |
|
398 | + if ( isset( $tokens[ $i ][ 'nested_parenthesis' ] ) === true ) { |
|
399 | + $nestedParenthesis = $tokens[ $i ][ 'nested_parenthesis' ]; |
|
400 | + $nestedOpenParenthesis = array_keys( $nestedParenthesis ); |
|
401 | + $lastOpenParenthesis = array_pop( $nestedOpenParenthesis ); |
|
402 | 402 | |
403 | 403 | $previousNonEmpty = $phpcsFile->findPrevious( |
404 | 404 | Tokens::$emptyTokens, |
405 | - ($lastOpenParenthesis - 1), |
|
405 | + ( $lastOpenParenthesis - 1 ), |
|
406 | 406 | null, |
407 | 407 | true, |
408 | 408 | null, |
409 | 409 | true |
410 | 410 | ); |
411 | 411 | |
412 | - if (isset($this->validUseOutsideObject[$tokens[$previousNonEmpty]['code']])) { |
|
412 | + if ( isset( $this->validUseOutsideObject[ $tokens[ $previousNonEmpty ][ 'code' ] ] ) ) { |
|
413 | 413 | continue; |
414 | 414 | } |
415 | 415 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function register() |
37 | 37 | { |
38 | - return array(\T_VARIABLE); |
|
38 | + return array( \T_VARIABLE ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -47,41 +47,41 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function process(File $phpcsFile, $stackPtr) |
|
50 | + public function process( File $phpcsFile, $stackPtr ) |
|
51 | 51 | { |
52 | - if ($this->supportsAbove('7.0') === false) { |
|
52 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $tokens = $phpcsFile->getTokens(); |
57 | 57 | |
58 | 58 | // Verify that the next token is a square open bracket. If not, bow out. |
59 | - $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
59 | + $nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
60 | 60 | |
61 | - if ($nextToken === false || $tokens[$nextToken]['code'] !== \T_OPEN_SQUARE_BRACKET || isset($tokens[$nextToken]['bracket_closer']) === false) { |
|
61 | + if ( $nextToken === false || $tokens[ $nextToken ][ 'code' ] !== \T_OPEN_SQUARE_BRACKET || isset( $tokens[ $nextToken ][ 'bracket_closer' ] ) === false ) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | 65 | // The previous non-empty token has to be a $, -> or ::. |
66 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
67 | - if ($prevToken === false || \in_array($tokens[$prevToken]['code'], array(\T_DOLLAR, \T_OBJECT_OPERATOR, \T_DOUBLE_COLON), true) === false) { |
|
66 | + $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
|
67 | + if ( $prevToken === false || \in_array( $tokens[ $prevToken ][ 'code' ], array( \T_DOLLAR, \T_OBJECT_OPERATOR, \T_DOUBLE_COLON ), true ) === false ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // For static object calls, it only applies when this is a function call. |
72 | - if ($tokens[$prevToken]['code'] === \T_DOUBLE_COLON) { |
|
73 | - $hasBrackets = $tokens[$nextToken]['bracket_closer']; |
|
74 | - while (($hasBrackets = $phpcsFile->findNext(Tokens::$emptyTokens, ($hasBrackets + 1), null, true, null, true)) !== false) { |
|
75 | - if ($tokens[$hasBrackets]['code'] === \T_OPEN_SQUARE_BRACKET) { |
|
76 | - if (isset($tokens[$hasBrackets]['bracket_closer'])) { |
|
77 | - $hasBrackets = $tokens[$hasBrackets]['bracket_closer']; |
|
72 | + if ( $tokens[ $prevToken ][ 'code' ] === \T_DOUBLE_COLON ) { |
|
73 | + $hasBrackets = $tokens[ $nextToken ][ 'bracket_closer' ]; |
|
74 | + while ( ( $hasBrackets = $phpcsFile->findNext( Tokens::$emptyTokens, ( $hasBrackets + 1 ), null, true, null, true ) ) !== false ) { |
|
75 | + if ( $tokens[ $hasBrackets ][ 'code' ] === \T_OPEN_SQUARE_BRACKET ) { |
|
76 | + if ( isset( $tokens[ $hasBrackets ][ 'bracket_closer' ] ) ) { |
|
77 | + $hasBrackets = $tokens[ $hasBrackets ][ 'bracket_closer' ]; |
|
78 | 78 | continue; |
79 | 79 | } else { |
80 | 80 | // Live coding. |
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - } elseif ($tokens[$hasBrackets]['code'] === \T_OPEN_PARENTHESIS) { |
|
84 | + } elseif ( $tokens[ $hasBrackets ][ 'code' ] === \T_OPEN_PARENTHESIS ) { |
|
85 | 85 | // Caught! |
86 | 86 | break; |
87 | 87 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | // Now let's also prevent false positives when used with self and static which still work fine. |
95 | - $classToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), null, true, null, true); |
|
96 | - if ($classToken !== false) { |
|
97 | - if ($tokens[$classToken]['code'] === \T_STATIC || $tokens[$classToken]['code'] === \T_SELF) { |
|
95 | + $classToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prevToken - 1 ), null, true, null, true ); |
|
96 | + if ( $classToken !== false ) { |
|
97 | + if ( $tokens[ $classToken ][ 'code' ] === \T_STATIC || $tokens[ $classToken ][ 'code' ] === \T_SELF ) { |
|
98 | 98 | return; |
99 | - } elseif ($tokens[$classToken]['code'] === \T_STRING && $tokens[$classToken]['content'] === 'self') { |
|
99 | + } elseif ( $tokens[ $classToken ][ 'code' ] === \T_STRING && $tokens[ $classToken ][ 'content' ] === 'self' ) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | } |