@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function register() |
93 | 93 | { |
94 | - return array(\T_VARIABLE); |
|
94 | + return array( \T_VARIABLE ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
@@ -104,35 +104,35 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function process(File $phpcsFile, $stackPtr) |
|
107 | + public function process( File $phpcsFile, $stackPtr ) |
|
108 | 108 | { |
109 | - if ($this->supportsAbove('5.3') === false) { |
|
109 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $tokens = $phpcsFile->getTokens(); |
114 | - $varName = substr($tokens[$stackPtr]['content'], 1); |
|
114 | + $varName = substr( $tokens[ $stackPtr ][ 'content' ], 1 ); |
|
115 | 115 | |
116 | - if (isset($this->removedGlobalVariables[$varName]) === false) { |
|
116 | + if ( isset( $this->removedGlobalVariables[ $varName ] ) === false ) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | |
120 | - if ($this->isClassProperty($phpcsFile, $stackPtr) === true) { |
|
120 | + if ( $this->isClassProperty( $phpcsFile, $stackPtr ) === true ) { |
|
121 | 121 | // Ok, so this was a class property declaration, not our concern. |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Check for static usage of class properties shadowing the removed global variables. |
126 | - if ($this->inClassScope($phpcsFile, $stackPtr, false) === true) { |
|
127 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
128 | - if ($prevToken !== false && $tokens[$prevToken]['code'] === \T_DOUBLE_COLON) { |
|
126 | + if ( $this->inClassScope( $phpcsFile, $stackPtr, false ) === true ) { |
|
127 | + $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
|
128 | + if ( $prevToken !== false && $tokens[ $prevToken ][ 'code' ] === \T_DOUBLE_COLON ) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Do some additional checks for the $php_errormsg variable. |
134 | - if ($varName === 'php_errormsg' |
|
135 | - && $this->isTargetPHPErrormsgVar($phpcsFile, $stackPtr, $tokens) === false |
|
134 | + if ( $varName === 'php_errormsg' |
|
135 | + && $this->isTargetPHPErrormsgVar( $phpcsFile, $stackPtr, $tokens ) === false |
|
136 | 136 | ) { |
137 | 137 | return; |
138 | 138 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $itemInfo = array( |
142 | 142 | 'name' => $varName, |
143 | 143 | ); |
144 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
144 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return array Version and other information about the item. |
154 | 154 | */ |
155 | - public function getItemArray(array $itemInfo) |
|
155 | + public function getItemArray( array $itemInfo ) |
|
156 | 156 | { |
157 | - return $this->removedGlobalVariables[$itemInfo['name']]; |
|
157 | + return $this->removedGlobalVariables[ $itemInfo[ 'name' ] ]; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
181 | + protected function filterErrorMsg( $error, array $itemInfo, array $errorInfo ) |
|
182 | 182 | { |
183 | - if ($itemInfo['name'] === 'php_errormsg') { |
|
184 | - $error = str_replace('Global', 'The', $error); |
|
183 | + if ( $itemInfo[ 'name' ] === 'php_errormsg' ) { |
|
184 | + $error = str_replace( 'Global', 'The', $error ); |
|
185 | 185 | } |
186 | 186 | return $error; |
187 | 187 | } |
@@ -196,59 +196,59 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return bool |
198 | 198 | */ |
199 | - private function isTargetPHPErrormsgVar(File $phpcsFile, $stackPtr, array $tokens) |
|
199 | + private function isTargetPHPErrormsgVar( File $phpcsFile, $stackPtr, array $tokens ) |
|
200 | 200 | { |
201 | 201 | $scopeStart = 0; |
202 | 202 | |
203 | 203 | /* |
204 | 204 | * If the variable is detected within the scope of a function/closure, limit the checking. |
205 | 205 | */ |
206 | - $function = $phpcsFile->getCondition($stackPtr, \T_CLOSURE); |
|
207 | - if ($function === false) { |
|
208 | - $function = $phpcsFile->getCondition($stackPtr, \T_FUNCTION); |
|
206 | + $function = $phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); |
|
207 | + if ( $function === false ) { |
|
208 | + $function = $phpcsFile->getCondition( $stackPtr, \T_FUNCTION ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | // It could also be a function param, which is not in the function scope. |
212 | - if ($function === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) { |
|
213 | - $nestedParentheses = $tokens[$stackPtr]['nested_parenthesis']; |
|
214 | - $parenthesisCloser = end($nestedParentheses); |
|
215 | - if (isset($tokens[$parenthesisCloser]['parenthesis_owner']) |
|
216 | - && ($tokens[$tokens[$parenthesisCloser]['parenthesis_owner']]['code'] === \T_FUNCTION |
|
217 | - || $tokens[$tokens[$parenthesisCloser]['parenthesis_owner']]['code'] === \T_CLOSURE) |
|
212 | + if ( $function === false && isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) { |
|
213 | + $nestedParentheses = $tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
214 | + $parenthesisCloser = end( $nestedParentheses ); |
|
215 | + if ( isset( $tokens[ $parenthesisCloser ][ 'parenthesis_owner' ] ) |
|
216 | + && ( $tokens[ $tokens[ $parenthesisCloser ][ 'parenthesis_owner' ] ][ 'code' ] === \T_FUNCTION |
|
217 | + || $tokens[ $tokens[ $parenthesisCloser ][ 'parenthesis_owner' ] ][ 'code' ] === \T_CLOSURE ) |
|
218 | 218 | ) { |
219 | - $function = $tokens[$parenthesisCloser]['parenthesis_owner']; |
|
219 | + $function = $tokens[ $parenthesisCloser ][ 'parenthesis_owner' ]; |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ($function !== false) { |
|
224 | - $scopeStart = $tokens[$function]['scope_opener']; |
|
223 | + if ( $function !== false ) { |
|
224 | + $scopeStart = $tokens[ $function ][ 'scope_opener' ]; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /* |
228 | 228 | * Now, let's do some additional checks. |
229 | 229 | */ |
230 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
230 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
231 | 231 | |
232 | 232 | // Is the variable being used as an array ? |
233 | - if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['code'] === \T_OPEN_SQUARE_BRACKET) { |
|
233 | + if ( $nextNonEmpty !== false && $tokens[ $nextNonEmpty ][ 'code' ] === \T_OPEN_SQUARE_BRACKET ) { |
|
234 | 234 | // The PHP native variable is a string, so this is probably not it |
235 | 235 | // (except for array access to string, but why would you in this case ?). |
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Is this a variable assignment ? |
240 | - if ($nextNonEmpty !== false |
|
241 | - && isset(Tokens::$assignmentTokens[$tokens[$nextNonEmpty]['code']]) === true |
|
240 | + if ( $nextNonEmpty !== false |
|
241 | + && isset( Tokens::$assignmentTokens[ $tokens[ $nextNonEmpty ][ 'code' ] ] ) === true |
|
242 | 242 | ) { |
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | 246 | // Is this a function param shadowing the PHP native one ? |
247 | - if ($function !== false) { |
|
248 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $function); |
|
249 | - if (\is_array($parameters) === true && empty($parameters) === false) { |
|
250 | - foreach ($parameters as $param) { |
|
251 | - if ($param['name'] === '$php_errormsg') { |
|
247 | + if ( $function !== false ) { |
|
248 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $function ); |
|
249 | + if ( \is_array( $parameters ) === true && empty( $parameters ) === false ) { |
|
250 | + foreach ( $parameters as $param ) { |
|
251 | + if ( $param[ 'name' ] === '$php_errormsg' ) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | } |
@@ -265,24 +265,24 @@ discard block |
||
265 | 265 | ); |
266 | 266 | |
267 | 267 | // Walk back and see if there is an assignment to the variable within the same scope. |
268 | - for ($i = ($stackPtr - 1); $i >= $scopeStart; $i--) { |
|
269 | - if ($tokens[$i]['code'] === \T_CLOSE_CURLY_BRACKET |
|
270 | - && isset($tokens[$i]['scope_condition']) |
|
271 | - && isset($skipPast[$tokens[$tokens[$i]['scope_condition']]['type']]) |
|
268 | + for ( $i = ( $stackPtr - 1 ); $i >= $scopeStart; $i-- ) { |
|
269 | + if ( $tokens[ $i ][ 'code' ] === \T_CLOSE_CURLY_BRACKET |
|
270 | + && isset( $tokens[ $i ][ 'scope_condition' ] ) |
|
271 | + && isset( $skipPast[ $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'type' ] ] ) |
|
272 | 272 | ) { |
273 | 273 | // Skip past functions, classes etc. |
274 | - $i = $tokens[$i]['scope_condition']; |
|
274 | + $i = $tokens[ $i ][ 'scope_condition' ]; |
|
275 | 275 | continue; |
276 | 276 | } |
277 | 277 | |
278 | - if ($tokens[$i]['code'] !== \T_VARIABLE || $tokens[$i]['content'] !== '$php_errormsg') { |
|
278 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE || $tokens[ $i ][ 'content' ] !== '$php_errormsg' ) { |
|
279 | 279 | continue; |
280 | 280 | } |
281 | 281 | |
282 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
282 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
|
283 | 283 | |
284 | - if ($nextNonEmpty !== false |
|
285 | - && isset(Tokens::$assignmentTokens[$tokens[$nextNonEmpty]['code']]) === true |
|
284 | + if ( $nextNonEmpty !== false |
|
285 | + && isset( Tokens::$assignmentTokens[ $tokens[ $nextNonEmpty ][ 'code' ] ] ) === true |
|
286 | 286 | ) { |
287 | 287 | return false; |
288 | 288 | } |
@@ -117,48 +117,48 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return void |
119 | 119 | */ |
120 | - public function process(File $phpcsFile, $stackPtr) |
|
120 | + public function process( File $phpcsFile, $stackPtr ) |
|
121 | 121 | { |
122 | - if ($this->supportsAbove('7.0') === false) { |
|
122 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $tokens = $phpcsFile->getTokens(); |
127 | 127 | |
128 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
128 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
129 | 129 | // Abstract function, interface function, live coding or parse error. |
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - $scopeOpener = $tokens[$stackPtr]['scope_opener']; |
|
134 | - $scopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
133 | + $scopeOpener = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
134 | + $scopeCloser = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
135 | 135 | |
136 | 136 | // Does the function declaration have parameters ? |
137 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
138 | - if (empty($params)) { |
|
137 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
138 | + if ( empty( $params ) ) { |
|
139 | 139 | // No named arguments found, so no risk of them being changed. |
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $paramNames = array(); |
144 | - foreach ($params as $param) { |
|
145 | - $paramNames[] = $param['name']; |
|
144 | + foreach ( $params as $param ) { |
|
145 | + $paramNames[ ] = $param[ 'name' ]; |
|
146 | 146 | } |
147 | 147 | |
148 | - for ($i = ($scopeOpener + 1); $i < $scopeCloser; $i++) { |
|
149 | - if (isset($this->skipPastNested[$tokens[$i]['type']]) && isset($tokens[$i]['scope_closer'])) { |
|
148 | + for ( $i = ( $scopeOpener + 1 ); $i < $scopeCloser; $i++ ) { |
|
149 | + if ( isset( $this->skipPastNested[ $tokens[ $i ][ 'type' ] ] ) && isset( $tokens[ $i ][ 'scope_closer' ] ) ) { |
|
150 | 150 | // Skip past nested structures. |
151 | - $i = $tokens[$i]['scope_closer']; |
|
151 | + $i = $tokens[ $i ][ 'scope_closer' ]; |
|
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | - if ($tokens[$i]['code'] !== \T_STRING) { |
|
155 | + if ( $tokens[ $i ][ 'code' ] !== \T_STRING ) { |
|
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | - $foundFunctionName = strtolower($tokens[$i]['content']); |
|
159 | + $foundFunctionName = strtolower( $tokens[ $i ][ 'content' ] ); |
|
160 | 160 | |
161 | - if (isset($this->changedFunctions[$foundFunctionName]) === false) { |
|
161 | + if ( isset( $this->changedFunctions[ $foundFunctionName ] ) === false ) { |
|
162 | 162 | // Not one of the target functions. |
163 | 163 | continue; |
164 | 164 | } |
@@ -166,22 +166,22 @@ discard block |
||
166 | 166 | /* |
167 | 167 | * Ok, so is this really a function call to one of the PHP native functions ? |
168 | 168 | */ |
169 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
170 | - if ($next === false || $tokens[$next]['code'] !== \T_OPEN_PARENTHESIS) { |
|
169 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
|
170 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
171 | 171 | // Live coding, parse error or not a function call. |
172 | 172 | continue; |
173 | 173 | } |
174 | 174 | |
175 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true); |
|
176 | - if ($prev !== false) { |
|
177 | - if (isset($this->noneFunctionCallIndicators[$tokens[$prev]['code']])) { |
|
175 | + $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true ); |
|
176 | + if ( $prev !== false ) { |
|
177 | + if ( isset( $this->noneFunctionCallIndicators[ $tokens[ $prev ][ 'code' ] ] ) ) { |
|
178 | 178 | continue; |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Check for namespaced functions, ie: \foo\bar() not \bar(). |
182 | - if ($tokens[ $prev ]['code'] === \T_NS_SEPARATOR) { |
|
183 | - $pprev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); |
|
184 | - if ($pprev !== false && $tokens[ $pprev ]['code'] === \T_STRING) { |
|
182 | + if ( $tokens[ $prev ][ 'code' ] === \T_NS_SEPARATOR ) { |
|
183 | + $pprev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true ); |
|
184 | + if ( $pprev !== false && $tokens[ $pprev ][ 'code' ] === \T_STRING ) { |
|
185 | 185 | continue; |
186 | 186 | } |
187 | 187 | } |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | /* |
191 | 191 | * Address some special cases. |
192 | 192 | */ |
193 | - if ($foundFunctionName !== 'func_get_args') { |
|
194 | - $paramOne = $this->getFunctionCallParameter($phpcsFile, $i, 1); |
|
195 | - if ($paramOne !== false) { |
|
196 | - switch ($foundFunctionName) { |
|
193 | + if ( $foundFunctionName !== 'func_get_args' ) { |
|
194 | + $paramOne = $this->getFunctionCallParameter( $phpcsFile, $i, 1 ); |
|
195 | + if ( $paramOne !== false ) { |
|
196 | + switch ( $foundFunctionName ) { |
|
197 | 197 | /* |
198 | 198 | * Check if `debug_(print_)backtrace()` is called with the |
199 | 199 | * `DEBUG_BACKTRACE_IGNORE_ARGS` option. |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | case 'debug_print_backtrace': |
203 | 203 | $hasIgnoreArgs = $phpcsFile->findNext( |
204 | 204 | \T_STRING, |
205 | - $paramOne['start'], |
|
206 | - ($paramOne['end'] + 1), |
|
205 | + $paramOne[ 'start' ], |
|
206 | + ( $paramOne[ 'end' ] + 1 ), |
|
207 | 207 | false, |
208 | 208 | 'DEBUG_BACKTRACE_IGNORE_ARGS' |
209 | 209 | ); |
210 | 210 | |
211 | - if ($hasIgnoreArgs !== false) { |
|
211 | + if ( $hasIgnoreArgs !== false ) { |
|
212 | 212 | // Debug_backtrace() called with ignore args option. |
213 | 213 | continue 2; |
214 | 214 | } |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | * Should be exceptionally rare and can - if needs be - be addressed at a later stage.}} |
226 | 226 | */ |
227 | 227 | case 'func_get_arg': |
228 | - $number = $phpcsFile->findNext(\T_LNUMBER, $paramOne['start'], ($paramOne['end'] + 1)); |
|
229 | - if ($number !== false) { |
|
230 | - $argNumber = $tokens[$number]['content']; |
|
228 | + $number = $phpcsFile->findNext( \T_LNUMBER, $paramOne[ 'start' ], ( $paramOne[ 'end' ] + 1 ) ); |
|
229 | + if ( $number !== false ) { |
|
230 | + $argNumber = $tokens[ $number ][ 'content' ]; |
|
231 | 231 | |
232 | - if (isset($paramNames[$argNumber]) === false) { |
|
232 | + if ( isset( $paramNames[ $argNumber ] ) === false ) { |
|
233 | 233 | // Requesting a non-named additional parameter. Ignore. |
234 | 234 | continue 2; |
235 | 235 | } |
@@ -246,28 +246,28 @@ discard block |
||
246 | 246 | * {@internal Note: This does not take offset calculations into account! |
247 | 247 | * Should be exceptionally rare and can - if needs be - be addressed at a later stage.}} |
248 | 248 | */ |
249 | - if ($prev !== false && $tokens[$prev]['code'] === \T_OPEN_PARENTHESIS) { |
|
249 | + if ( $prev !== false && $tokens[ $prev ][ 'code' ] === \T_OPEN_PARENTHESIS ) { |
|
250 | 250 | |
251 | - $maybeFunctionCall = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); |
|
252 | - if ($maybeFunctionCall !== false |
|
253 | - && $tokens[$maybeFunctionCall]['code'] === \T_STRING |
|
254 | - && ($tokens[$maybeFunctionCall]['content'] === 'array_slice' |
|
255 | - || $tokens[$maybeFunctionCall]['content'] === 'array_splice') |
|
251 | + $maybeFunctionCall = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true ); |
|
252 | + if ( $maybeFunctionCall !== false |
|
253 | + && $tokens[ $maybeFunctionCall ][ 'code' ] === \T_STRING |
|
254 | + && ( $tokens[ $maybeFunctionCall ][ 'content' ] === 'array_slice' |
|
255 | + || $tokens[ $maybeFunctionCall ][ 'content' ] === 'array_splice' ) |
|
256 | 256 | ) { |
257 | - $parentFuncParamTwo = $this->getFunctionCallParameter($phpcsFile, $maybeFunctionCall, 2); |
|
257 | + $parentFuncParamTwo = $this->getFunctionCallParameter( $phpcsFile, $maybeFunctionCall, 2 ); |
|
258 | 258 | $number = $phpcsFile->findNext( |
259 | 259 | \T_LNUMBER, |
260 | - $parentFuncParamTwo['start'], |
|
261 | - ($parentFuncParamTwo['end'] + 1) |
|
260 | + $parentFuncParamTwo[ 'start' ], |
|
261 | + ( $parentFuncParamTwo[ 'end' ] + 1 ) |
|
262 | 262 | ); |
263 | 263 | |
264 | - if ($number !== false && isset($paramNames[$tokens[$number]['content']]) === false) { |
|
264 | + if ( $number !== false && isset( $paramNames[ $tokens[ $number ][ 'content' ] ] ) === false ) { |
|
265 | 265 | // Requesting non-named additional parameters. Ignore. |
266 | - continue ; |
|
266 | + continue; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | // Slice starts at a named argument, but we know which params are being accessed. |
270 | - $paramNamesSubset = \array_slice($paramNames, $tokens[$number]['content']); |
|
270 | + $paramNamesSubset = \array_slice( $paramNames, $tokens[ $number ][ 'content' ] ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
@@ -280,34 +280,34 @@ discard block |
||
280 | 280 | * |
281 | 281 | * Note: We already know that $next is the open parenthesis of the function call. |
282 | 282 | */ |
283 | - if ($foundFunctionName === 'debug_backtrace' && isset($tokens[$next]['parenthesis_closer'])) { |
|
283 | + if ( $foundFunctionName === 'debug_backtrace' && isset( $tokens[ $next ][ 'parenthesis_closer' ] ) ) { |
|
284 | 284 | $afterParenthesis = $phpcsFile->findNext( |
285 | 285 | Tokens::$emptyTokens, |
286 | - ($tokens[$next]['parenthesis_closer'] + 1), |
|
286 | + ( $tokens[ $next ][ 'parenthesis_closer' ] + 1 ), |
|
287 | 287 | null, |
288 | 288 | true |
289 | 289 | ); |
290 | 290 | |
291 | - if ($tokens[$afterParenthesis]['code'] === \T_OPEN_SQUARE_BRACKET |
|
292 | - && isset($tokens[$afterParenthesis]['bracket_closer']) |
|
291 | + if ( $tokens[ $afterParenthesis ][ 'code' ] === \T_OPEN_SQUARE_BRACKET |
|
292 | + && isset( $tokens[ $afterParenthesis ][ 'bracket_closer' ] ) |
|
293 | 293 | ) { |
294 | 294 | $afterStackFrame = $phpcsFile->findNext( |
295 | 295 | Tokens::$emptyTokens, |
296 | - ($tokens[$afterParenthesis]['bracket_closer'] + 1), |
|
296 | + ( $tokens[ $afterParenthesis ][ 'bracket_closer' ] + 1 ), |
|
297 | 297 | null, |
298 | 298 | true |
299 | 299 | ); |
300 | 300 | |
301 | - if ($tokens[$afterStackFrame]['code'] === \T_OPEN_SQUARE_BRACKET |
|
302 | - && isset($tokens[$afterStackFrame]['bracket_closer']) |
|
301 | + if ( $tokens[ $afterStackFrame ][ 'code' ] === \T_OPEN_SQUARE_BRACKET |
|
302 | + && isset( $tokens[ $afterStackFrame ][ 'bracket_closer' ] ) |
|
303 | 303 | ) { |
304 | 304 | $arrayIndex = $phpcsFile->findNext( |
305 | 305 | \T_CONSTANT_ENCAPSED_STRING, |
306 | - ($afterStackFrame + 1), |
|
307 | - $tokens[$afterStackFrame]['bracket_closer'] |
|
306 | + ( $afterStackFrame + 1 ), |
|
307 | + $tokens[ $afterStackFrame ][ 'bracket_closer' ] |
|
308 | 308 | ); |
309 | 309 | |
310 | - if ($arrayIndex !== false && $this->stripQuotes($tokens[$arrayIndex]['content']) !== 'args') { |
|
310 | + if ( $arrayIndex !== false && $this->stripQuotes( $tokens[ $arrayIndex ][ 'content' ] ) !== 'args' ) { |
|
311 | 311 | continue; |
312 | 312 | } |
313 | 313 | } |
@@ -320,39 +320,39 @@ discard block |
||
320 | 320 | * being assigned to one of the parameters, i.e.: |
321 | 321 | * `$param = func_get_args();`. |
322 | 322 | */ |
323 | - $startOfStatement = PHPCSHelper::findStartOfStatement($phpcsFile, $i, $this->ignoreForStartOfStatement); |
|
323 | + $startOfStatement = PHPCSHelper::findStartOfStatement( $phpcsFile, $i, $this->ignoreForStartOfStatement ); |
|
324 | 324 | |
325 | 325 | /* |
326 | 326 | * Ok, so we've found one of the target functions in the right scope. |
327 | 327 | * Now, let's check if any of the passed parameters were touched. |
328 | 328 | */ |
329 | 329 | $scanResult = 'clean'; |
330 | - for ($j = ($scopeOpener + 1); $j < $startOfStatement; $j++) { |
|
331 | - if (isset($this->skipPastNested[$tokens[$j]['type']]) |
|
332 | - && isset($tokens[$j]['scope_closer']) |
|
330 | + for ( $j = ( $scopeOpener + 1 ); $j < $startOfStatement; $j++ ) { |
|
331 | + if ( isset( $this->skipPastNested[ $tokens[ $j ][ 'type' ] ] ) |
|
332 | + && isset( $tokens[ $j ][ 'scope_closer' ] ) |
|
333 | 333 | ) { |
334 | 334 | // Skip past nested structures. |
335 | - $j = $tokens[$j]['scope_closer']; |
|
335 | + $j = $tokens[ $j ][ 'scope_closer' ]; |
|
336 | 336 | continue; |
337 | 337 | } |
338 | 338 | |
339 | - if ($tokens[$j]['code'] !== \T_VARIABLE) { |
|
339 | + if ( $tokens[ $j ][ 'code' ] !== \T_VARIABLE ) { |
|
340 | 340 | continue; |
341 | 341 | } |
342 | 342 | |
343 | - if ($foundFunctionName === 'func_get_arg' && isset($argNumber)) { |
|
344 | - if (isset($paramNames[$argNumber]) |
|
345 | - && $tokens[$j]['content'] !== $paramNames[$argNumber] |
|
343 | + if ( $foundFunctionName === 'func_get_arg' && isset( $argNumber ) ) { |
|
344 | + if ( isset( $paramNames[ $argNumber ] ) |
|
345 | + && $tokens[ $j ][ 'content' ] !== $paramNames[ $argNumber ] |
|
346 | 346 | ) { |
347 | 347 | // Different param than the one requested by func_get_arg(). |
348 | 348 | continue; |
349 | 349 | } |
350 | - } elseif ($foundFunctionName === 'func_get_args' && isset($paramNamesSubset)) { |
|
351 | - if (\in_array($tokens[$j]['content'], $paramNamesSubset, true) === false) { |
|
350 | + } elseif ( $foundFunctionName === 'func_get_args' && isset( $paramNamesSubset ) ) { |
|
351 | + if ( \in_array( $tokens[ $j ][ 'content' ], $paramNamesSubset, true ) === false ) { |
|
352 | 352 | // Different param than the ones requested by func_get_args(). |
353 | 353 | continue; |
354 | 354 | } |
355 | - } elseif (\in_array($tokens[$j]['content'], $paramNames, true) === false) { |
|
355 | + } elseif ( \in_array( $tokens[ $j ][ 'content' ], $paramNames, true ) === false ) { |
|
356 | 356 | // Variable is not one of the function parameters. |
357 | 357 | continue; |
358 | 358 | } |
@@ -363,46 +363,46 @@ discard block |
||
363 | 363 | * assigned something ? |
364 | 364 | */ |
365 | 365 | $scanResult = 'warning'; |
366 | - if (isset($variableToken) === false) { |
|
366 | + if ( isset( $variableToken ) === false ) { |
|
367 | 367 | $variableToken = $j; |
368 | 368 | } |
369 | 369 | |
370 | - $beforeVar = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($j - 1), null, true); |
|
371 | - if ($beforeVar !== false && isset($this->plusPlusMinusMinus[$tokens[$beforeVar]['code']])) { |
|
370 | + $beforeVar = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $j - 1 ), null, true ); |
|
371 | + if ( $beforeVar !== false && isset( $this->plusPlusMinusMinus[ $tokens[ $beforeVar ][ 'code' ] ] ) ) { |
|
372 | 372 | // Variable is being (pre-)incremented/decremented. |
373 | 373 | $scanResult = 'error'; |
374 | 374 | $variableToken = $j; |
375 | 375 | break; |
376 | 376 | } |
377 | 377 | |
378 | - $afterVar = $phpcsFile->findNext(Tokens::$emptyTokens, ($j + 1), null, true); |
|
379 | - if ($afterVar === false) { |
|
378 | + $afterVar = $phpcsFile->findNext( Tokens::$emptyTokens, ( $j + 1 ), null, true ); |
|
379 | + if ( $afterVar === false ) { |
|
380 | 380 | // Shouldn't be possible, but just in case. |
381 | 381 | continue; |
382 | 382 | } |
383 | 383 | |
384 | - if (isset($this->plusPlusMinusMinus[$tokens[$afterVar]['code']])) { |
|
384 | + if ( isset( $this->plusPlusMinusMinus[ $tokens[ $afterVar ][ 'code' ] ] ) ) { |
|
385 | 385 | // Variable is being (post-)incremented/decremented. |
386 | 386 | $scanResult = 'error'; |
387 | 387 | $variableToken = $j; |
388 | 388 | break; |
389 | 389 | } |
390 | 390 | |
391 | - if ($tokens[$afterVar]['code'] === \T_OPEN_SQUARE_BRACKET |
|
392 | - && isset($tokens[$afterVar]['bracket_closer']) |
|
391 | + if ( $tokens[ $afterVar ][ 'code' ] === \T_OPEN_SQUARE_BRACKET |
|
392 | + && isset( $tokens[ $afterVar ][ 'bracket_closer' ] ) |
|
393 | 393 | ) { |
394 | 394 | // Skip past array access on the variable. |
395 | - while (($afterVar = $phpcsFile->findNext(Tokens::$emptyTokens, ($tokens[$afterVar]['bracket_closer'] + 1), null, true)) !== false) { |
|
396 | - if ($tokens[$afterVar]['code'] !== \T_OPEN_SQUARE_BRACKET |
|
397 | - || isset($tokens[$afterVar]['bracket_closer']) === false |
|
395 | + while ( ( $afterVar = $phpcsFile->findNext( Tokens::$emptyTokens, ( $tokens[ $afterVar ][ 'bracket_closer' ] + 1 ), null, true ) ) !== false ) { |
|
396 | + if ( $tokens[ $afterVar ][ 'code' ] !== \T_OPEN_SQUARE_BRACKET |
|
397 | + || isset( $tokens[ $afterVar ][ 'bracket_closer' ] ) === false |
|
398 | 398 | ) { |
399 | 399 | break; |
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | - if ($afterVar !== false |
|
405 | - && isset(Tokens::$assignmentTokens[$tokens[$afterVar]['code']]) |
|
404 | + if ( $afterVar !== false |
|
405 | + && isset( Tokens::$assignmentTokens[ $tokens[ $afterVar ][ 'code' ] ] ) |
|
406 | 406 | ) { |
407 | 407 | // Variable is being assigned something. |
408 | 408 | $scanResult = 'error'; |
@@ -411,29 +411,29 @@ discard block |
||
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
414 | - unset($argNumber, $paramNamesSubset); |
|
414 | + unset( $argNumber, $paramNamesSubset ); |
|
415 | 415 | |
416 | - if ($scanResult === 'clean') { |
|
416 | + if ( $scanResult === 'clean' ) { |
|
417 | 417 | continue; |
418 | 418 | } |
419 | 419 | |
420 | 420 | $error = 'Since PHP 7.0, functions inspecting arguments, like %1$s(), no longer report the original value as passed to a parameter, but will instead provide the current value. The parameter "%2$s" was %4$s on line %3$s.'; |
421 | 421 | $data = array( |
422 | 422 | $foundFunctionName, |
423 | - $tokens[$variableToken]['content'], |
|
424 | - $tokens[$variableToken]['line'], |
|
423 | + $tokens[ $variableToken ][ 'content' ], |
|
424 | + $tokens[ $variableToken ][ 'line' ], |
|
425 | 425 | ); |
426 | 426 | |
427 | - if ($scanResult === 'error') { |
|
428 | - $data[] = 'changed'; |
|
429 | - $phpcsFile->addError($error, $i, 'Changed', $data); |
|
427 | + if ( $scanResult === 'error' ) { |
|
428 | + $data[ ] = 'changed'; |
|
429 | + $phpcsFile->addError( $error, $i, 'Changed', $data ); |
|
430 | 430 | |
431 | - } elseif ($scanResult === 'warning') { |
|
432 | - $data[] = 'used, and possibly changed (by reference),'; |
|
433 | - $phpcsFile->addWarning($error, $i, 'NeedsInspection', $data); |
|
431 | + } elseif ( $scanResult === 'warning' ) { |
|
432 | + $data[ ] = 'used, and possibly changed (by reference),'; |
|
433 | + $phpcsFile->addWarning( $error, $i, 'NeedsInspection', $data ); |
|
434 | 434 | } |
435 | 435 | |
436 | - unset($variableToken); |
|
436 | + unset( $variableToken ); |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | public function register() |
158 | 158 | { |
159 | 159 | // Handle case-insensitivity of function names. |
160 | - $this->functionParameters = $this->arrayKeysToLowercase($this->functionParameters); |
|
160 | + $this->functionParameters = $this->arrayKeysToLowercase( $this->functionParameters ); |
|
161 | 161 | |
162 | - return array(\T_STRING); |
|
162 | + return array( \T_STRING ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - public function process(File $phpcsFile, $stackPtr) |
|
174 | + public function process( File $phpcsFile, $stackPtr ) |
|
175 | 175 | { |
176 | 176 | $tokens = $phpcsFile->getTokens(); |
177 | 177 | |
@@ -182,37 +182,37 @@ discard block |
||
182 | 182 | \T_CONST => true, |
183 | 183 | ); |
184 | 184 | |
185 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
186 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
185 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
186 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
187 | 187 | // Not a call to a PHP function. |
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | - $function = $tokens[$stackPtr]['content']; |
|
192 | - $functionLc = strtolower($function); |
|
191 | + $function = $tokens[ $stackPtr ][ 'content' ]; |
|
192 | + $functionLc = strtolower( $function ); |
|
193 | 193 | |
194 | - if (isset($this->functionParameters[$functionLc]) === false) { |
|
194 | + if ( isset( $this->functionParameters[ $functionLc ] ) === false ) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | - $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr); |
|
199 | - $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
198 | + $parameterCount = $this->getFunctionCallParameterCount( $phpcsFile, $stackPtr ); |
|
199 | + $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
200 | 200 | |
201 | 201 | // If the parameter count returned > 0, we know there will be valid open parenthesis. |
202 | - if ($parameterCount === 0 && $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) { |
|
202 | + if ( $parameterCount === 0 && $tokens[ $openParenthesis ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | 206 | $parameterOffsetFound = $parameterCount - 1; |
207 | 207 | |
208 | - foreach ($this->functionParameters[$functionLc] as $offset => $parameterDetails) { |
|
209 | - if ($offset > $parameterOffsetFound) { |
|
208 | + foreach ( $this->functionParameters[ $functionLc ] as $offset => $parameterDetails ) { |
|
209 | + if ( $offset > $parameterOffsetFound ) { |
|
210 | 210 | $itemInfo = array( |
211 | 211 | 'name' => $function, |
212 | 212 | 'nameLc' => $functionLc, |
213 | 213 | 'offset' => $offset, |
214 | 214 | ); |
215 | - $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo); |
|
215 | + $this->handleFeature( $phpcsFile, $openParenthesis, $itemInfo ); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | } |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return bool |
227 | 227 | */ |
228 | - protected function shouldThrowError(array $errorInfo) |
|
228 | + protected function shouldThrowError( array $errorInfo ) |
|
229 | 229 | { |
230 | - return ($errorInfo['requiredVersion'] !== ''); |
|
230 | + return ( $errorInfo[ 'requiredVersion' ] !== '' ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return array Version and other information about the item. |
240 | 240 | */ |
241 | - public function getItemArray(array $itemInfo) |
|
241 | + public function getItemArray( array $itemInfo ) |
|
242 | 242 | { |
243 | - return $this->functionParameters[$itemInfo['nameLc']][$itemInfo['offset']]; |
|
243 | + return $this->functionParameters[ $itemInfo[ 'nameLc' ] ][ $itemInfo[ 'offset' ] ]; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | protected function getNonVersionArrayKeys() |
253 | 253 | { |
254 | - return array('name'); |
|
254 | + return array( 'name' ); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -263,24 +263,24 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @return array |
265 | 265 | */ |
266 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
266 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
267 | 267 | { |
268 | 268 | $errorInfo = array( |
269 | 269 | 'paramName' => '', |
270 | 270 | 'requiredVersion' => '', |
271 | 271 | ); |
272 | 272 | |
273 | - $versionArray = $this->getVersionArray($itemArray); |
|
273 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
274 | 274 | |
275 | - if (empty($versionArray) === false) { |
|
276 | - foreach ($versionArray as $version => $required) { |
|
277 | - if ($required === true && $this->supportsBelow($version) === true) { |
|
278 | - $errorInfo['requiredVersion'] = $version; |
|
275 | + if ( empty( $versionArray ) === false ) { |
|
276 | + foreach ( $versionArray as $version => $required ) { |
|
277 | + if ( $required === true && $this->supportsBelow( $version ) === true ) { |
|
278 | + $errorInfo[ 'requiredVersion' ] = $version; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - $errorInfo['paramName'] = $itemArray['name']; |
|
283 | + $errorInfo[ 'paramName' ] = $itemArray[ 'name' ]; |
|
284 | 284 | |
285 | 285 | return $errorInfo; |
286 | 286 | } |
@@ -309,16 +309,16 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return void |
311 | 311 | */ |
312 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
312 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
313 | 313 | { |
314 | 314 | $error = $this->getErrorMsgTemplate(); |
315 | - $errorCode = $this->stringToErrorCode($itemInfo['name'] . '_' . $errorInfo['paramName']) . 'Missing'; |
|
315 | + $errorCode = $this->stringToErrorCode( $itemInfo[ 'name' ] . '_' . $errorInfo[ 'paramName' ] ) . 'Missing'; |
|
316 | 316 | $data = array( |
317 | - $errorInfo['paramName'], |
|
318 | - $itemInfo['name'], |
|
319 | - $errorInfo['requiredVersion'], |
|
317 | + $errorInfo[ 'paramName' ], |
|
318 | + $itemInfo[ 'name' ], |
|
319 | + $errorInfo[ 'requiredVersion' ], |
|
320 | 320 | ); |
321 | 321 | |
322 | - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); |
|
322 | + $phpcsFile->addError( $error, $stackPtr, $errorCode, $data ); |
|
323 | 323 | } |
324 | 324 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function register() |
56 | 56 | { |
57 | - return array(\T_STRING); |
|
57 | + return array( \T_STRING ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - public function process(File $phpcsFile, $stackPtr) |
|
70 | + public function process( File $phpcsFile, $stackPtr ) |
|
71 | 71 | { |
72 | 72 | $tokens = $phpcsFile->getTokens(); |
73 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
74 | - if (isset($this->targetFunctions[$functionLc]) === false) { |
|
73 | + $functionLc = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
74 | + if ( isset( $this->targetFunctions[ $functionLc ] ) === false ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Next non-empty token should be the open parenthesis. |
79 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
80 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
79 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
80 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | \T_NEW => true, |
89 | 89 | ); |
90 | 90 | |
91 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
92 | - if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) { |
|
91 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
92 | + if ( isset( $ignore[ $tokens[ $prevNonEmpty ][ 'code' ] ] ) === true ) { |
|
93 | 93 | // Not a call to a PHP function. |
94 | 94 | return; |
95 | - } elseif ($tokens[$prevNonEmpty]['code'] === \T_NS_SEPARATOR && $tokens[$prevNonEmpty - 1]['code'] === \T_STRING) { |
|
95 | + } elseif ( $tokens[ $prevNonEmpty ][ 'code' ] === \T_NS_SEPARATOR && $tokens[ $prevNonEmpty - 1 ][ 'code' ] === \T_STRING ) { |
|
96 | 96 | // Namespaced function. |
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | - $data = $tokens[$stackPtr]['content']; |
|
100 | + $data = $tokens[ $stackPtr ][ 'content' ]; |
|
101 | 101 | |
102 | 102 | /* |
103 | 103 | * Check for usage of the functions in the global scope. |
@@ -105,52 +105,52 @@ discard block |
||
105 | 105 | * As PHPCS can not determine whether a file is included from within a function in |
106 | 106 | * another file, so always throw a warning/error. |
107 | 107 | */ |
108 | - if ($phpcsFile->hasCondition($stackPtr, array(\T_FUNCTION, \T_CLOSURE)) === false) { |
|
108 | + if ( $phpcsFile->hasCondition( $stackPtr, array( \T_FUNCTION, \T_CLOSURE ) ) === false ) { |
|
109 | 109 | $isError = false; |
110 | 110 | $message = 'Use of %s() outside of a user-defined function is only supported if the file is included from within a user-defined function in another file prior to PHP 5.3.'; |
111 | 111 | |
112 | - if ($this->supportsAbove('5.3') === true) { |
|
112 | + if ( $this->supportsAbove( '5.3' ) === true ) { |
|
113 | 113 | $isError = true; |
114 | 114 | $message .= ' As of PHP 5.3, it is no longer supported at all.'; |
115 | 115 | } |
116 | 116 | |
117 | - $this->addMessage($phpcsFile, $message, $stackPtr, $isError, 'OutsideFunctionScope', $data); |
|
117 | + $this->addMessage( $phpcsFile, $message, $stackPtr, $isError, 'OutsideFunctionScope', $data ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /* |
121 | 121 | * Check for usage of the functions as a parameter in a function call. |
122 | 122 | */ |
123 | - if ($this->supportsBelow('5.2') === false) { |
|
123 | + if ( $this->supportsBelow( '5.2' ) === false ) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) { |
|
127 | + if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | 131 | $throwError = false; |
132 | 132 | |
133 | - $closer = end($tokens[$stackPtr]['nested_parenthesis']); |
|
134 | - if (isset($tokens[$closer]['parenthesis_owner']) |
|
135 | - && $tokens[$tokens[$closer]['parenthesis_owner']]['type'] === 'T_CLOSURE' |
|
133 | + $closer = end( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
134 | + if ( isset( $tokens[ $closer ][ 'parenthesis_owner' ] ) |
|
135 | + && $tokens[ $tokens[ $closer ][ 'parenthesis_owner' ] ][ 'type' ] === 'T_CLOSURE' |
|
136 | 136 | ) { |
137 | 137 | $throwError = true; |
138 | 138 | } else { |
139 | - $opener = key($tokens[$stackPtr]['nested_parenthesis']); |
|
140 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true); |
|
141 | - if ($tokens[$prevNonEmpty]['code'] !== \T_STRING) { |
|
139 | + $opener = key( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
140 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true ); |
|
141 | + if ( $tokens[ $prevNonEmpty ][ 'code' ] !== \T_STRING ) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | - $prevPrevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevNonEmpty - 1), null, true); |
|
146 | - if ($tokens[$prevPrevNonEmpty]['code'] === \T_FUNCTION) { |
|
145 | + $prevPrevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prevNonEmpty - 1 ), null, true ); |
|
146 | + if ( $tokens[ $prevPrevNonEmpty ][ 'code' ] === \T_FUNCTION ) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $throwError = true; |
151 | 151 | } |
152 | 152 | |
153 | - if ($throwError === false) { |
|
153 | + if ( $throwError === false ) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 |
@@ -963,9 +963,9 @@ discard block |
||
963 | 963 | public function register() |
964 | 964 | { |
965 | 965 | // Handle case-insensitivity of function names. |
966 | - $this->removedFunctions = $this->arrayKeysToLowercase($this->removedFunctions); |
|
966 | + $this->removedFunctions = $this->arrayKeysToLowercase( $this->removedFunctions ); |
|
967 | 967 | |
968 | - return array(\T_STRING); |
|
968 | + return array( \T_STRING ); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | * |
979 | 979 | * @return void |
980 | 980 | */ |
981 | - public function process(File $phpcsFile, $stackPtr) |
|
981 | + public function process( File $phpcsFile, $stackPtr ) |
|
982 | 982 | { |
983 | 983 | $tokens = $phpcsFile->getTokens(); |
984 | 984 | |
@@ -992,16 +992,16 @@ discard block |
||
992 | 992 | \T_NS_SEPARATOR => true, |
993 | 993 | ); |
994 | 994 | |
995 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
996 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
995 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
996 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
997 | 997 | // Not a call to a PHP function. |
998 | 998 | return; |
999 | 999 | } |
1000 | 1000 | |
1001 | - $function = $tokens[$stackPtr]['content']; |
|
1002 | - $functionLc = strtolower($function); |
|
1001 | + $function = $tokens[ $stackPtr ][ 'content' ]; |
|
1002 | + $functionLc = strtolower( $function ); |
|
1003 | 1003 | |
1004 | - if (isset($this->removedFunctions[$functionLc]) === false) { |
|
1004 | + if ( isset( $this->removedFunctions[ $functionLc ] ) === false ) { |
|
1005 | 1005 | return; |
1006 | 1006 | } |
1007 | 1007 | |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | 'name' => $function, |
1010 | 1010 | 'nameLc' => $functionLc, |
1011 | 1011 | ); |
1012 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
1012 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | |
@@ -1020,9 +1020,9 @@ discard block |
||
1020 | 1020 | * |
1021 | 1021 | * @return array Version and other information about the item. |
1022 | 1022 | */ |
1023 | - public function getItemArray(array $itemInfo) |
|
1023 | + public function getItemArray( array $itemInfo ) |
|
1024 | 1024 | { |
1025 | - return $this->removedFunctions[$itemInfo['nameLc']]; |
|
1025 | + return $this->removedFunctions[ $itemInfo[ 'nameLc' ] ]; |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | public function register() |
76 | 76 | { |
77 | 77 | // Handle case-insensitivity of function names. |
78 | - $this->removedFunctionParameters = $this->arrayKeysToLowercase($this->removedFunctionParameters); |
|
78 | + $this->removedFunctionParameters = $this->arrayKeysToLowercase( $this->removedFunctionParameters ); |
|
79 | 79 | |
80 | - return array(\T_STRING); |
|
80 | + return array( \T_STRING ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return void |
91 | 91 | */ |
92 | - public function process(File $phpcsFile, $stackPtr) |
|
92 | + public function process( File $phpcsFile, $stackPtr ) |
|
93 | 93 | { |
94 | 94 | $tokens = $phpcsFile->getTokens(); |
95 | 95 | |
@@ -100,36 +100,36 @@ discard block |
||
100 | 100 | \T_CONST => true, |
101 | 101 | ); |
102 | 102 | |
103 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
104 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
103 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
104 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
105 | 105 | // Not a call to a PHP function. |
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | - $function = $tokens[$stackPtr]['content']; |
|
110 | - $functionLc = strtolower($function); |
|
109 | + $function = $tokens[ $stackPtr ][ 'content' ]; |
|
110 | + $functionLc = strtolower( $function ); |
|
111 | 111 | |
112 | - if (isset($this->removedFunctionParameters[$functionLc]) === false) { |
|
112 | + if ( isset( $this->removedFunctionParameters[ $functionLc ] ) === false ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr); |
|
117 | - if ($parameterCount === 0) { |
|
116 | + $parameterCount = $this->getFunctionCallParameterCount( $phpcsFile, $stackPtr ); |
|
117 | + if ( $parameterCount === 0 ) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // If the parameter count returned > 0, we know there will be valid open parenthesis. |
122 | - $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
122 | + $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
123 | 123 | $parameterOffsetFound = $parameterCount - 1; |
124 | 124 | |
125 | - foreach ($this->removedFunctionParameters[$functionLc] as $offset => $parameterDetails) { |
|
126 | - if ($offset <= $parameterOffsetFound) { |
|
125 | + foreach ( $this->removedFunctionParameters[ $functionLc ] as $offset => $parameterDetails ) { |
|
126 | + if ( $offset <= $parameterOffsetFound ) { |
|
127 | 127 | $itemInfo = array( |
128 | 128 | 'name' => $function, |
129 | 129 | 'nameLc' => $functionLc, |
130 | 130 | 'offset' => $offset, |
131 | 131 | ); |
132 | - $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo); |
|
132 | + $this->handleFeature( $phpcsFile, $openParenthesis, $itemInfo ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @return array Version and other information about the item. |
144 | 144 | */ |
145 | - public function getItemArray(array $itemInfo) |
|
145 | + public function getItemArray( array $itemInfo ) |
|
146 | 146 | { |
147 | - return $this->removedFunctionParameters[$itemInfo['nameLc']][$itemInfo['offset']]; |
|
147 | + return $this->removedFunctionParameters[ $itemInfo[ 'nameLc' ] ][ $itemInfo[ 'offset' ] ]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function getNonVersionArrayKeys() |
157 | 157 | { |
158 | - return array('name'); |
|
158 | + return array( 'name' ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
170 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
171 | 171 | { |
172 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
173 | - $errorInfo['paramName'] = $itemArray['name']; |
|
172 | + $errorInfo = parent::getErrorInfo( $itemArray, $itemInfo ); |
|
173 | + $errorInfo[ 'paramName' ] = $itemArray[ 'name' ]; |
|
174 | 174 | |
175 | 175 | return $errorInfo; |
176 | 176 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
187 | + protected function getItemName( array $itemInfo, array $errorInfo ) |
|
188 | 188 | { |
189 | - return $itemInfo['name'] . '_' . $errorInfo['paramName']; |
|
189 | + return $itemInfo[ 'name' ] . '_' . $errorInfo[ 'paramName' ]; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return array |
212 | 212 | */ |
213 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
213 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
214 | 214 | { |
215 | - array_shift($data); |
|
216 | - array_unshift($data, $errorInfo['paramName'], $itemInfo['name']); |
|
215 | + array_shift( $data ); |
|
216 | + array_unshift( $data, $errorInfo[ 'paramName' ], $itemInfo[ 'name' ] ); |
|
217 | 217 | return $data; |
218 | 218 | } |
219 | 219 | } |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | - protected function shouldThrowError(array $errorInfo) |
|
60 | + protected function shouldThrowError( array $errorInfo ) |
|
61 | 61 | { |
62 | - return ($errorInfo['optionalDeprecated'] !== '' |
|
63 | - || $errorInfo['optionalRemoved'] !== '' |
|
64 | - || $errorInfo['optionalRecommended'] !== ''); |
|
62 | + return ( $errorInfo[ 'optionalDeprecated' ] !== '' |
|
63 | + || $errorInfo[ 'optionalRemoved' ] !== '' |
|
64 | + || $errorInfo[ 'optionalRecommended' ] !== '' ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
76 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
77 | 77 | { |
78 | 78 | $errorInfo = array( |
79 | 79 | 'paramName' => '', |
@@ -83,24 +83,24 @@ discard block |
||
83 | 83 | 'error' => false, |
84 | 84 | ); |
85 | 85 | |
86 | - $versionArray = $this->getVersionArray($itemArray); |
|
87 | - |
|
88 | - if (empty($versionArray) === false) { |
|
89 | - foreach ($versionArray as $version => $required) { |
|
90 | - if ($this->supportsAbove($version) === true) { |
|
91 | - if ($required === true && $errorInfo['optionalRemoved'] === '') { |
|
92 | - $errorInfo['optionalRemoved'] = $version; |
|
93 | - $errorInfo['error'] = true; |
|
94 | - } elseif ($required === 'recommended' && $errorInfo['optionalRecommended'] === '') { |
|
95 | - $errorInfo['optionalRecommended'] = $version; |
|
96 | - } elseif ($errorInfo['optionalDeprecated'] === '') { |
|
97 | - $errorInfo['optionalDeprecated'] = $version; |
|
86 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
87 | + |
|
88 | + if ( empty( $versionArray ) === false ) { |
|
89 | + foreach ( $versionArray as $version => $required ) { |
|
90 | + if ( $this->supportsAbove( $version ) === true ) { |
|
91 | + if ( $required === true && $errorInfo[ 'optionalRemoved' ] === '' ) { |
|
92 | + $errorInfo[ 'optionalRemoved' ] = $version; |
|
93 | + $errorInfo[ 'error' ] = true; |
|
94 | + } elseif ( $required === 'recommended' && $errorInfo[ 'optionalRecommended' ] === '' ) { |
|
95 | + $errorInfo[ 'optionalRecommended' ] = $version; |
|
96 | + } elseif ( $errorInfo[ 'optionalDeprecated' ] === '' ) { |
|
97 | + $errorInfo[ 'optionalDeprecated' ] = $version; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - $errorInfo['paramName'] = $itemArray['name']; |
|
103 | + $errorInfo[ 'paramName' ] = $itemArray[ 'name' ]; |
|
104 | 104 | |
105 | 105 | return $errorInfo; |
106 | 106 | } |
@@ -118,42 +118,42 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return void |
120 | 120 | */ |
121 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
121 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
122 | 122 | { |
123 | 123 | $error = 'The "%s" parameter for function %s() is missing. Passing this parameter is '; |
124 | - if ($errorInfo['optionalRecommended'] === '') { |
|
124 | + if ( $errorInfo[ 'optionalRecommended' ] === '' ) { |
|
125 | 125 | $error .= 'no longer optional. The optional nature of the parameter is '; |
126 | 126 | } else { |
127 | 127 | $error .= 'strongly recommended '; |
128 | 128 | } |
129 | 129 | |
130 | - $errorCode = $this->stringToErrorCode($itemInfo['name'] . '_' . $errorInfo['paramName']); |
|
130 | + $errorCode = $this->stringToErrorCode( $itemInfo[ 'name' ] . '_' . $errorInfo[ 'paramName' ] ); |
|
131 | 131 | $data = array( |
132 | - $errorInfo['paramName'], |
|
133 | - $itemInfo['name'], |
|
132 | + $errorInfo[ 'paramName' ], |
|
133 | + $itemInfo[ 'name' ], |
|
134 | 134 | ); |
135 | 135 | |
136 | - if ($errorInfo['optionalRecommended'] !== '') { |
|
136 | + if ( $errorInfo[ 'optionalRecommended' ] !== '' ) { |
|
137 | 137 | $error .= 'since PHP %s '; |
138 | 138 | $errorCode .= 'SoftRecommended'; |
139 | - $data[] = $errorInfo['optionalRecommended']; |
|
139 | + $data[ ] = $errorInfo[ 'optionalRecommended' ]; |
|
140 | 140 | } else { |
141 | - if ($errorInfo['optionalDeprecated'] !== '') { |
|
141 | + if ( $errorInfo[ 'optionalDeprecated' ] !== '' ) { |
|
142 | 142 | $error .= 'deprecated since PHP %s and '; |
143 | 143 | $errorCode .= 'SoftRequired'; |
144 | - $data[] = $errorInfo['optionalDeprecated']; |
|
144 | + $data[ ] = $errorInfo[ 'optionalDeprecated' ]; |
|
145 | 145 | } |
146 | 146 | |
147 | - if ($errorInfo['optionalRemoved'] !== '') { |
|
147 | + if ( $errorInfo[ 'optionalRemoved' ] !== '' ) { |
|
148 | 148 | $error .= 'removed since PHP %s and '; |
149 | 149 | $errorCode .= 'HardRequired'; |
150 | - $data[] = $errorInfo['optionalRemoved']; |
|
150 | + $data[ ] = $errorInfo[ 'optionalRemoved' ]; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Remove the last 'and' from the message. |
154 | - $error = substr($error, 0, (\strlen($error) - 5)); |
|
154 | + $error = substr( $error, 0, ( \strlen( $error ) - 5 ) ); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
157 | + $this->addMessage( $phpcsFile, $error, $stackPtr, $errorInfo[ 'error' ], $errorCode, $data ); |
|
158 | 158 | } |
159 | 159 | } |
@@ -1889,9 +1889,9 @@ discard block |
||
1889 | 1889 | public function register() |
1890 | 1890 | { |
1891 | 1891 | // Handle case-insensitivity of function names. |
1892 | - $this->newFunctions = $this->arrayKeysToLowercase($this->newFunctions); |
|
1892 | + $this->newFunctions = $this->arrayKeysToLowercase( $this->newFunctions ); |
|
1893 | 1893 | |
1894 | - return array(\T_STRING); |
|
1894 | + return array( \T_STRING ); |
|
1895 | 1895 | } |
1896 | 1896 | |
1897 | 1897 | /** |
@@ -1903,7 +1903,7 @@ discard block |
||
1903 | 1903 | * |
1904 | 1904 | * @return void |
1905 | 1905 | */ |
1906 | - public function process(File $phpcsFile, $stackPtr) |
|
1906 | + public function process( File $phpcsFile, $stackPtr ) |
|
1907 | 1907 | { |
1908 | 1908 | $tokens = $phpcsFile->getTokens(); |
1909 | 1909 | |
@@ -1914,20 +1914,20 @@ discard block |
||
1914 | 1914 | \T_CONST => true, |
1915 | 1915 | ); |
1916 | 1916 | |
1917 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
1918 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
1917 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
1918 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
1919 | 1919 | // Not a call to a PHP function. |
1920 | 1920 | return; |
1921 | 1921 | |
1922 | - } elseif ($tokens[$prevToken]['code'] === \T_NS_SEPARATOR && $tokens[$prevToken - 1]['code'] === \T_STRING) { |
|
1922 | + } elseif ( $tokens[ $prevToken ][ 'code' ] === \T_NS_SEPARATOR && $tokens[ $prevToken - 1 ][ 'code' ] === \T_STRING ) { |
|
1923 | 1923 | // Namespaced function. |
1924 | 1924 | return; |
1925 | 1925 | } |
1926 | 1926 | |
1927 | - $function = $tokens[$stackPtr]['content']; |
|
1928 | - $functionLc = strtolower($function); |
|
1927 | + $function = $tokens[ $stackPtr ][ 'content' ]; |
|
1928 | + $functionLc = strtolower( $function ); |
|
1929 | 1929 | |
1930 | - if (isset($this->newFunctions[$functionLc]) === false) { |
|
1930 | + if ( isset( $this->newFunctions[ $functionLc ] ) === false ) { |
|
1931 | 1931 | return; |
1932 | 1932 | } |
1933 | 1933 | |
@@ -1935,7 +1935,7 @@ discard block |
||
1935 | 1935 | 'name' => $function, |
1936 | 1936 | 'nameLc' => $functionLc, |
1937 | 1937 | ); |
1938 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
1938 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
1939 | 1939 | } |
1940 | 1940 | |
1941 | 1941 | |
@@ -1946,9 +1946,9 @@ discard block |
||
1946 | 1946 | * |
1947 | 1947 | * @return array Version and other information about the item. |
1948 | 1948 | */ |
1949 | - public function getItemArray(array $itemInfo) |
|
1949 | + public function getItemArray( array $itemInfo ) |
|
1950 | 1950 | { |
1951 | - return $this->newFunctions[$itemInfo['nameLc']]; |
|
1951 | + return $this->newFunctions[ $itemInfo[ 'nameLc' ] ]; |
|
1952 | 1952 | } |
1953 | 1953 | |
1954 | 1954 |
@@ -942,9 +942,9 @@ discard block |
||
942 | 942 | public function register() |
943 | 943 | { |
944 | 944 | // Handle case-insensitivity of function names. |
945 | - $this->newFunctionParameters = $this->arrayKeysToLowercase($this->newFunctionParameters); |
|
945 | + $this->newFunctionParameters = $this->arrayKeysToLowercase( $this->newFunctionParameters ); |
|
946 | 946 | |
947 | - return array(\T_STRING); |
|
947 | + return array( \T_STRING ); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * |
957 | 957 | * @return void |
958 | 958 | */ |
959 | - public function process(File $phpcsFile, $stackPtr) |
|
959 | + public function process( File $phpcsFile, $stackPtr ) |
|
960 | 960 | { |
961 | 961 | $tokens = $phpcsFile->getTokens(); |
962 | 962 | |
@@ -967,36 +967,36 @@ discard block |
||
967 | 967 | \T_CONST => true, |
968 | 968 | ); |
969 | 969 | |
970 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
971 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
970 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
971 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
972 | 972 | // Not a call to a PHP function. |
973 | 973 | return; |
974 | 974 | } |
975 | 975 | |
976 | - $function = $tokens[$stackPtr]['content']; |
|
977 | - $functionLc = strtolower($function); |
|
976 | + $function = $tokens[ $stackPtr ][ 'content' ]; |
|
977 | + $functionLc = strtolower( $function ); |
|
978 | 978 | |
979 | - if (isset($this->newFunctionParameters[$functionLc]) === false) { |
|
979 | + if ( isset( $this->newFunctionParameters[ $functionLc ] ) === false ) { |
|
980 | 980 | return; |
981 | 981 | } |
982 | 982 | |
983 | - $parameterCount = $this->getFunctionCallParameterCount($phpcsFile, $stackPtr); |
|
984 | - if ($parameterCount === 0) { |
|
983 | + $parameterCount = $this->getFunctionCallParameterCount( $phpcsFile, $stackPtr ); |
|
984 | + if ( $parameterCount === 0 ) { |
|
985 | 985 | return; |
986 | 986 | } |
987 | 987 | |
988 | 988 | // If the parameter count returned > 0, we know there will be valid open parenthesis. |
989 | - $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
989 | + $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
990 | 990 | $parameterOffsetFound = $parameterCount - 1; |
991 | 991 | |
992 | - foreach ($this->newFunctionParameters[$functionLc] as $offset => $parameterDetails) { |
|
993 | - if ($offset <= $parameterOffsetFound) { |
|
992 | + foreach ( $this->newFunctionParameters[ $functionLc ] as $offset => $parameterDetails ) { |
|
993 | + if ( $offset <= $parameterOffsetFound ) { |
|
994 | 994 | $itemInfo = array( |
995 | 995 | 'name' => $function, |
996 | 996 | 'nameLc' => $functionLc, |
997 | 997 | 'offset' => $offset, |
998 | 998 | ); |
999 | - $this->handleFeature($phpcsFile, $openParenthesis, $itemInfo); |
|
999 | + $this->handleFeature( $phpcsFile, $openParenthesis, $itemInfo ); |
|
1000 | 1000 | } |
1001 | 1001 | } |
1002 | 1002 | } |
@@ -1009,9 +1009,9 @@ discard block |
||
1009 | 1009 | * |
1010 | 1010 | * @return array Version and other information about the item. |
1011 | 1011 | */ |
1012 | - public function getItemArray(array $itemInfo) |
|
1012 | + public function getItemArray( array $itemInfo ) |
|
1013 | 1013 | { |
1014 | - return $this->newFunctionParameters[$itemInfo['nameLc']][$itemInfo['offset']]; |
|
1014 | + return $this->newFunctionParameters[ $itemInfo[ 'nameLc' ] ][ $itemInfo[ 'offset' ] ]; |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | */ |
1023 | 1023 | protected function getNonVersionArrayKeys() |
1024 | 1024 | { |
1025 | - return array('name'); |
|
1025 | + return array( 'name' ); |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | |
@@ -1034,10 +1034,10 @@ discard block |
||
1034 | 1034 | * |
1035 | 1035 | * @return array |
1036 | 1036 | */ |
1037 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
1037 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
1038 | 1038 | { |
1039 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
1040 | - $errorInfo['paramName'] = $itemArray['name']; |
|
1039 | + $errorInfo = parent::getErrorInfo( $itemArray, $itemInfo ); |
|
1040 | + $errorInfo[ 'paramName' ] = $itemArray[ 'name' ]; |
|
1041 | 1041 | |
1042 | 1042 | return $errorInfo; |
1043 | 1043 | } |
@@ -1051,9 +1051,9 @@ discard block |
||
1051 | 1051 | * |
1052 | 1052 | * @return string |
1053 | 1053 | */ |
1054 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
1054 | + protected function getItemName( array $itemInfo, array $errorInfo ) |
|
1055 | 1055 | { |
1056 | - return $itemInfo['name'] . '_' . $errorInfo['paramName']; |
|
1056 | + return $itemInfo[ 'name' ] . '_' . $errorInfo[ 'paramName' ]; |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
@@ -1077,10 +1077,10 @@ discard block |
||
1077 | 1077 | * |
1078 | 1078 | * @return array |
1079 | 1079 | */ |
1080 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
1080 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
1081 | 1081 | { |
1082 | - array_shift($data); |
|
1083 | - array_unshift($data, $itemInfo['name'], $errorInfo['paramName']); |
|
1082 | + array_shift( $data ); |
|
1083 | + array_unshift( $data, $itemInfo[ 'name' ], $errorInfo[ 'paramName' ] ); |
|
1084 | 1084 | return $data; |
1085 | 1085 | } |
1086 | 1086 | } |