@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - return array(\T_FOREACH); |
|
39 | + return array( \T_FOREACH ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,23 +48,23 @@ 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('5.4') === false) { |
|
53 | + if ( $this->supportsBelow( '5.4' ) === false ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | |
59 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
59 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
64 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
63 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
64 | + $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
65 | 65 | |
66 | - $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer); |
|
67 | - if ($asToken === false) { |
|
66 | + $asToken = $phpcsFile->findNext( \T_AS, ( $opener + 1 ), $closer ); |
|
67 | + if ( $asToken === false ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | * Note: referencing $key is not allowed in any version, so this should only find referenced $values. |
73 | 73 | * If it does find a referenced key, it would be a parse error anyway. |
74 | 74 | */ |
75 | - $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer); |
|
76 | - if ($hasReference === false) { |
|
75 | + $hasReference = $phpcsFile->findNext( \T_BITWISE_AND, ( $asToken + 1 ), $closer ); |
|
76 | + if ( $hasReference === false ) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | 80 | $nestingLevel = 0; |
81 | - if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) { |
|
82 | - $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']); |
|
81 | + if ( $asToken !== ( $opener + 1 ) && isset( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] ) ) { |
|
82 | + $nestingLevel = \count( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] ); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) { |
|
85 | + if ( $this->isVariable( $phpcsFile, ( $opener + 1 ), $asToken, $nestingLevel ) === true ) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'strict_types' => array( |
49 | 49 | '5.6' => false, |
50 | 50 | '7.0' => true, |
51 | - 'valid_values' => array(1), |
|
51 | + 'valid_values' => array( 1 ), |
|
52 | 52 | ), |
53 | 53 | ); |
54 | 54 | |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | public function register() |
70 | 70 | { |
71 | 71 | $this->ignoreTokens = Tokens::$emptyTokens; |
72 | - $this->ignoreTokens[\T_EQUAL] = \T_EQUAL; |
|
72 | + $this->ignoreTokens[ \T_EQUAL ] = \T_EQUAL; |
|
73 | 73 | |
74 | - return array(\T_DECLARE); |
|
74 | + return array( \T_DECLARE ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -84,56 +84,56 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return void |
86 | 86 | */ |
87 | - public function process(File $phpcsFile, $stackPtr) |
|
87 | + public function process( File $phpcsFile, $stackPtr ) |
|
88 | 88 | { |
89 | 89 | $tokens = $phpcsFile->getTokens(); |
90 | 90 | |
91 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === true) { |
|
92 | - $openParenthesis = $tokens[$stackPtr]['parenthesis_opener']; |
|
93 | - $closeParenthesis = $tokens[$stackPtr]['parenthesis_closer']; |
|
91 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true ) { |
|
92 | + $openParenthesis = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
93 | + $closeParenthesis = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
94 | 94 | } else { |
95 | - if (version_compare(PHPCSHelper::getVersion(), '2.3.4', '>=')) { |
|
95 | + if ( version_compare( PHPCSHelper::getVersion(), '2.3.4', '>=' ) ) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Deal with PHPCS 2.3.0-2.3.3 which do not yet set the parenthesis properly for declare statements. |
100 | - $openParenthesis = $phpcsFile->findNext(\T_OPEN_PARENTHESIS, ($stackPtr + 1), null, false, null, true); |
|
101 | - if ($openParenthesis === false || isset($tokens[$openParenthesis]['parenthesis_closer']) === false) { |
|
100 | + $openParenthesis = $phpcsFile->findNext( \T_OPEN_PARENTHESIS, ( $stackPtr + 1 ), null, false, null, true ); |
|
101 | + if ( $openParenthesis === false || isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) === false ) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | - $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer']; |
|
104 | + $closeParenthesis = $tokens[ $openParenthesis ][ 'parenthesis_closer' ]; |
|
105 | 105 | } |
106 | 106 | |
107 | - $directivePtr = $phpcsFile->findNext(\T_STRING, ($openParenthesis + 1), $closeParenthesis, false); |
|
108 | - if ($directivePtr === false) { |
|
107 | + $directivePtr = $phpcsFile->findNext( \T_STRING, ( $openParenthesis + 1 ), $closeParenthesis, false ); |
|
108 | + if ( $directivePtr === false ) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $directiveContent = $tokens[$directivePtr]['content']; |
|
112 | + $directiveContent = $tokens[ $directivePtr ][ 'content' ]; |
|
113 | 113 | |
114 | - if (isset($this->newDirectives[$directiveContent]) === false) { |
|
114 | + if ( isset( $this->newDirectives[ $directiveContent ] ) === false ) { |
|
115 | 115 | $error = 'Declare can only be used with the directives %s. Found: %s'; |
116 | 116 | $data = array( |
117 | - implode(', ', array_keys($this->newDirectives)), |
|
117 | + implode( ', ', array_keys( $this->newDirectives ) ), |
|
118 | 118 | $directiveContent, |
119 | 119 | ); |
120 | 120 | |
121 | - $phpcsFile->addError($error, $stackPtr, 'InvalidDirectiveFound', $data); |
|
121 | + $phpcsFile->addError( $error, $stackPtr, 'InvalidDirectiveFound', $data ); |
|
122 | 122 | |
123 | 123 | } else { |
124 | 124 | // Check for valid directive for version. |
125 | 125 | $itemInfo = array( |
126 | 126 | 'name' => $directiveContent, |
127 | 127 | ); |
128 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
128 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
129 | 129 | |
130 | 130 | // Check for valid directive value. |
131 | - $valuePtr = $phpcsFile->findNext($this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true); |
|
132 | - if ($valuePtr === false) { |
|
131 | + $valuePtr = $phpcsFile->findNext( $this->ignoreTokens, $directivePtr + 1, $closeParenthesis, true ); |
|
132 | + if ( $valuePtr === false ) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | - $this->addWarningOnInvalidValue($phpcsFile, $valuePtr, $directiveContent); |
|
136 | + $this->addWarningOnInvalidValue( $phpcsFile, $valuePtr, $directiveContent ); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - protected function shouldThrowError(array $errorInfo) |
|
148 | + protected function shouldThrowError( array $errorInfo ) |
|
149 | 149 | { |
150 | - return ($errorInfo['not_in_version'] !== '' || $errorInfo['conditional_version'] !== ''); |
|
150 | + return ( $errorInfo[ 'not_in_version' ] !== '' || $errorInfo[ 'conditional_version' ] !== '' ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return array Version and other information about the item. |
160 | 160 | */ |
161 | - public function getItemArray(array $itemInfo) |
|
161 | + public function getItemArray( array $itemInfo ) |
|
162 | 162 | { |
163 | - return $this->newDirectives[$itemInfo['name']]; |
|
163 | + return $this->newDirectives[ $itemInfo[ 'name' ] ]; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return array |
188 | 188 | */ |
189 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
189 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
190 | 190 | { |
191 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
192 | - $errorInfo['conditional_version'] = ''; |
|
193 | - $errorInfo['condition'] = ''; |
|
191 | + $errorInfo = parent::getErrorInfo( $itemArray, $itemInfo ); |
|
192 | + $errorInfo[ 'conditional_version' ] = ''; |
|
193 | + $errorInfo[ 'condition' ] = ''; |
|
194 | 194 | |
195 | - $versionArray = $this->getVersionArray($itemArray); |
|
195 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
196 | 196 | |
197 | - if (empty($versionArray) === false) { |
|
198 | - foreach ($versionArray as $version => $present) { |
|
199 | - if (\is_string($present) === true && $this->supportsBelow($version) === true) { |
|
197 | + if ( empty( $versionArray ) === false ) { |
|
198 | + foreach ( $versionArray as $version => $present ) { |
|
199 | + if ( \is_string( $present ) === true && $this->supportsBelow( $version ) === true ) { |
|
200 | 200 | // We cannot test for compilation option (ok, except by scraping the output of phpinfo...). |
201 | - $errorInfo['conditional_version'] = $version; |
|
202 | - $errorInfo['condition'] = $present; |
|
201 | + $errorInfo[ 'conditional_version' ] = $version; |
|
202 | + $errorInfo[ 'condition' ] = $present; |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | } |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return void |
233 | 233 | */ |
234 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
234 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
235 | 235 | { |
236 | - if ($errorInfo['not_in_version'] !== '') { |
|
237 | - parent::addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
|
238 | - } elseif ($errorInfo['conditional_version'] !== '') { |
|
236 | + if ( $errorInfo[ 'not_in_version' ] !== '' ) { |
|
237 | + parent::addError( $phpcsFile, $stackPtr, $itemInfo, $errorInfo ); |
|
238 | + } elseif ( $errorInfo[ 'conditional_version' ] !== '' ) { |
|
239 | 239 | $error = 'Directive %s is present in PHP version %s but will be disregarded unless PHP is compiled with %s'; |
240 | - $errorCode = $this->stringToErrorCode($itemInfo['name']) . 'WithConditionFound'; |
|
240 | + $errorCode = $this->stringToErrorCode( $itemInfo[ 'name' ] ) . 'WithConditionFound'; |
|
241 | 241 | $data = array( |
242 | - $itemInfo['name'], |
|
243 | - $errorInfo['conditional_version'], |
|
244 | - $errorInfo['condition'], |
|
242 | + $itemInfo[ 'name' ], |
|
243 | + $errorInfo[ 'conditional_version' ], |
|
244 | + $errorInfo[ 'condition' ], |
|
245 | 245 | ); |
246 | 246 | |
247 | - $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data); |
|
247 | + $phpcsFile->addWarning( $error, $stackPtr, $errorCode, $data ); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -259,36 +259,36 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return void |
261 | 261 | */ |
262 | - protected function addWarningOnInvalidValue(File $phpcsFile, $stackPtr, $directive) |
|
262 | + protected function addWarningOnInvalidValue( File $phpcsFile, $stackPtr, $directive ) |
|
263 | 263 | { |
264 | 264 | $tokens = $phpcsFile->getTokens(); |
265 | 265 | |
266 | - $value = $tokens[$stackPtr]['content']; |
|
267 | - if (isset(Tokens::$stringTokens[$tokens[$stackPtr]['code']]) === true) { |
|
268 | - $value = $this->stripQuotes($value); |
|
266 | + $value = $tokens[ $stackPtr ][ 'content' ]; |
|
267 | + if ( isset( Tokens::$stringTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true ) { |
|
268 | + $value = $this->stripQuotes( $value ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | $isError = false; |
272 | - if (isset($this->newDirectives[$directive]['valid_values'])) { |
|
273 | - if (\in_array($value, $this->newDirectives[$directive]['valid_values']) === false) { |
|
272 | + if ( isset( $this->newDirectives[ $directive ][ 'valid_values' ] ) ) { |
|
273 | + if ( \in_array( $value, $this->newDirectives[ $directive ][ 'valid_values' ] ) === false ) { |
|
274 | 274 | $isError = true; |
275 | 275 | } |
276 | - } elseif (isset($this->newDirectives[$directive]['valid_value_callback'])) { |
|
277 | - $valid = \call_user_func(array($this, $this->newDirectives[$directive]['valid_value_callback']), $value); |
|
278 | - if ($valid === false) { |
|
276 | + } elseif ( isset( $this->newDirectives[ $directive ][ 'valid_value_callback' ] ) ) { |
|
277 | + $valid = \call_user_func( array( $this, $this->newDirectives[ $directive ][ 'valid_value_callback' ] ), $value ); |
|
278 | + if ( $valid === false ) { |
|
279 | 279 | $isError = true; |
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - if ($isError === true) { |
|
283 | + if ( $isError === true ) { |
|
284 | 284 | $error = 'The execution directive %s does not seem to have a valid value. Please review. Found: %s'; |
285 | - $errorCode = $this->stringToErrorCode($directive) . 'InvalidValueFound'; |
|
285 | + $errorCode = $this->stringToErrorCode( $directive ) . 'InvalidValueFound'; |
|
286 | 286 | $data = array( |
287 | 287 | $directive, |
288 | 288 | $value, |
289 | 289 | ); |
290 | 290 | |
291 | - $phpcsFile->addWarning($error, $stackPtr, $errorCode, $data); |
|
291 | + $phpcsFile->addWarning( $error, $stackPtr, $errorCode, $data ); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function isNumeric($value) |
|
305 | + protected function isNumeric( $value ) |
|
306 | 306 | { |
307 | - return is_numeric($value); |
|
307 | + return is_numeric( $value ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return bool |
319 | 319 | */ |
320 | - protected function validEncoding($value) |
|
320 | + protected function validEncoding( $value ) |
|
321 | 321 | { |
322 | 322 | static $encodings; |
323 | - if (isset($encodings) === false && function_exists('mb_list_encodings')) { |
|
323 | + if ( isset( $encodings ) === false && function_exists( 'mb_list_encodings' ) ) { |
|
324 | 324 | $encodings = mb_list_encodings(); |
325 | 325 | } |
326 | 326 | |
327 | - if (empty($encodings) || \is_array($encodings) === false) { |
|
327 | + if ( empty( $encodings ) || \is_array( $encodings ) === false ) { |
|
328 | 328 | // If we can't test the encoding, let it pass through. |
329 | 329 | return true; |
330 | 330 | } |
331 | 331 | |
332 | - return \in_array($value, $encodings, true); |
|
332 | + return \in_array( $value, $encodings, true ); |
|
333 | 333 | } |
334 | 334 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | \T_CLOSURE, |
101 | 101 | ); |
102 | 102 | |
103 | - if (\defined('T_RETURN_TYPE')) { |
|
104 | - $tokens[] = \T_RETURN_TYPE; |
|
103 | + if ( \defined( 'T_RETURN_TYPE' ) ) { |
|
104 | + $tokens[ ] = \T_RETURN_TYPE; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return $tokens; |
@@ -117,33 +117,33 @@ 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 | 122 | $tokens = $phpcsFile->getTokens(); |
123 | 123 | |
124 | 124 | // Deal with older PHPCS version which don't recognize return type hints |
125 | 125 | // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
126 | - if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) { |
|
127 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
128 | - if ($returnTypeHint !== false) { |
|
126 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_FUNCTION || $tokens[ $stackPtr ][ 'code' ] === \T_CLOSURE ) { |
|
127 | + $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr ); |
|
128 | + if ( $returnTypeHint !== false ) { |
|
129 | 129 | $stackPtr = $returnTypeHint; |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) { |
|
133 | + if ( isset( $this->newTypes[ $tokens[ $stackPtr ][ 'content' ] ] ) === true ) { |
|
134 | 134 | $itemInfo = array( |
135 | - 'name' => $tokens[$stackPtr]['content'], |
|
135 | + 'name' => $tokens[ $stackPtr ][ 'content' ], |
|
136 | 136 | ); |
137 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
137 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
138 | 138 | } |
139 | 139 | // Handle class name based return types. |
140 | - elseif ($tokens[$stackPtr]['code'] === \T_STRING |
|
141 | - || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE) |
|
140 | + elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING |
|
141 | + || ( \defined( 'T_RETURN_TYPE' ) && $tokens[ $stackPtr ][ 'code' ] === \T_RETURN_TYPE ) |
|
142 | 142 | ) { |
143 | 143 | $itemInfo = array( |
144 | 144 | 'name' => 'Class name', |
145 | 145 | ); |
146 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
146 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return array Version and other information about the item. |
157 | 157 | */ |
158 | - public function getItemArray(array $itemInfo) |
|
158 | + public function getItemArray( array $itemInfo ) |
|
159 | 159 | { |
160 | - return $this->newTypes[$itemInfo['name']]; |
|
160 | + return $this->newTypes[ $itemInfo[ 'name' ] ]; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 |
@@ -112,59 +112,59 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public function process(File $phpcsFile, $stackPtr) |
|
115 | + public function process( File $phpcsFile, $stackPtr ) |
|
116 | 116 | { |
117 | 117 | // Get all parameters from method signature. |
118 | - $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
119 | - if (empty($paramNames)) { |
|
118 | + $paramNames = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
119 | + if ( empty( $paramNames ) ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - $supportsPHP4 = $this->supportsBelow('4.4'); |
|
123 | + $supportsPHP4 = $this->supportsBelow( '4.4' ); |
|
124 | 124 | |
125 | - foreach ($paramNames as $param) { |
|
126 | - if ($param['type_hint'] === '') { |
|
125 | + foreach ( $paramNames as $param ) { |
|
126 | + if ( $param[ 'type_hint' ] === '' ) { |
|
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Strip off potential nullable indication. |
131 | - $typeHint = ltrim($param['type_hint'], '?'); |
|
131 | + $typeHint = ltrim( $param[ 'type_hint' ], '?' ); |
|
132 | 132 | |
133 | - if ($supportsPHP4 === true) { |
|
133 | + if ( $supportsPHP4 === true ) { |
|
134 | 134 | $phpcsFile->addError( |
135 | 135 | 'Type declarations were not present in PHP 4.4 or earlier.', |
136 | - $param['token'], |
|
136 | + $param[ 'token' ], |
|
137 | 137 | 'TypeHintFound' |
138 | 138 | ); |
139 | 139 | |
140 | - } elseif (isset($this->newTypes[$typeHint])) { |
|
140 | + } elseif ( isset( $this->newTypes[ $typeHint ] ) ) { |
|
141 | 141 | $itemInfo = array( |
142 | 142 | 'name' => $typeHint, |
143 | 143 | ); |
144 | - $this->handleFeature($phpcsFile, $param['token'], $itemInfo); |
|
144 | + $this->handleFeature( $phpcsFile, $param[ 'token' ], $itemInfo ); |
|
145 | 145 | |
146 | 146 | // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error. |
147 | 147 | // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error |
148 | 148 | // will be thrown. |
149 | - if (($typeHint === 'self' || $typeHint === 'parent') |
|
150 | - && $this->inClassScope($phpcsFile, $stackPtr, false) === false |
|
151 | - && $this->supportsAbove('5.2') !== false |
|
149 | + if ( ( $typeHint === 'self' || $typeHint === 'parent' ) |
|
150 | + && $this->inClassScope( $phpcsFile, $stackPtr, false ) === false |
|
151 | + && $this->supportsAbove( '5.2' ) !== false |
|
152 | 152 | ) { |
153 | 153 | $phpcsFile->addError( |
154 | 154 | "'%s' type cannot be used outside of class scope", |
155 | - $param['token'], |
|
156 | - ucfirst($typeHint) . 'OutsideClassScopeFound', |
|
157 | - array($typeHint) |
|
155 | + $param[ 'token' ], |
|
156 | + ucfirst( $typeHint ) . 'OutsideClassScopeFound', |
|
157 | + array( $typeHint ) |
|
158 | 158 | ); |
159 | 159 | } |
160 | - } elseif (isset($this->invalidTypes[$typeHint])) { |
|
160 | + } elseif ( isset( $this->invalidTypes[ $typeHint ] ) ) { |
|
161 | 161 | $error = "'%s' is not a valid type declaration. Did you mean %s ?"; |
162 | 162 | $data = array( |
163 | 163 | $typeHint, |
164 | - $this->invalidTypes[$typeHint], |
|
164 | + $this->invalidTypes[ $typeHint ], |
|
165 | 165 | ); |
166 | 166 | |
167 | - $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data); |
|
167 | + $phpcsFile->addError( $error, $param[ 'token' ], 'InvalidTypeHintFound', $data ); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return array Version and other information about the item. |
179 | 179 | */ |
180 | - public function getItemArray(array $itemInfo) |
|
180 | + public function getItemArray( array $itemInfo ) |
|
181 | 181 | { |
182 | - return $this->newTypes[$itemInfo['name']]; |
|
182 | + return $this->newTypes[ $itemInfo[ 'name' ] ]; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function register() |
53 | 53 | { |
54 | - return array(\T_FUNCTION); |
|
54 | + return array( \T_FUNCTION ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - public function process(File $phpcsFile, $stackPtr) |
|
68 | + public function process( File $phpcsFile, $stackPtr ) |
|
69 | 69 | { |
70 | - if ($this->supportsAbove('5.3') === false) { |
|
70 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
75 | - if (strtolower($functionName) !== '__tostring') { |
|
74 | + $functionName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
75 | + if ( strtolower( $functionName ) !== '__tostring' ) { |
|
76 | 76 | // Not the right function. |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
80 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) === false ) { |
|
81 | 81 | // Function, not method. |
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
86 | - if (empty($params)) { |
|
85 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
86 | + if ( empty( $params ) ) { |
|
87 | 87 | // Function declared without parameters. |
88 | 88 | return; |
89 | 89 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(\T_USE); |
|
41 | + return array( \T_USE ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -50,65 +50,65 @@ 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->supportsAbove('7.1') === false) { |
|
55 | + if ( $this->supportsAbove( '7.1' ) === false ) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | 60 | |
61 | 61 | // Verify this use statement is used with a closure - if so, it has to have parenthesis before it. |
62 | - $previousNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
63 | - if ($previousNonEmpty === false || $tokens[$previousNonEmpty]['code'] !== \T_CLOSE_PARENTHESIS |
|
64 | - || isset($tokens[$previousNonEmpty]['parenthesis_opener']) === false |
|
62 | + $previousNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
|
63 | + if ( $previousNonEmpty === false || $tokens[ $previousNonEmpty ][ 'code' ] !== \T_CLOSE_PARENTHESIS |
|
64 | + || isset( $tokens[ $previousNonEmpty ][ 'parenthesis_opener' ] ) === false |
|
65 | 65 | ) { |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // ... and (a variable within) parenthesis after it. |
70 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
71 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
70 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
71 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | - if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) { |
|
75 | + if ( isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false ) { |
|
76 | 76 | // Live coding. |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - $closurePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($tokens[$previousNonEmpty]['parenthesis_opener'] - 1), null, true); |
|
81 | - if ($closurePtr === false || $tokens[$closurePtr]['code'] !== \T_CLOSURE) { |
|
80 | + $closurePtr = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $tokens[ $previousNonEmpty ][ 'parenthesis_opener' ] - 1 ), null, true ); |
|
81 | + if ( $closurePtr === false || $tokens[ $closurePtr ][ 'code' ] !== \T_CLOSURE ) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Get the parameters declared by the closure. |
86 | - $closureParams = PHPCSHelper::getMethodParameters($phpcsFile, $closurePtr); |
|
86 | + $closureParams = PHPCSHelper::getMethodParameters( $phpcsFile, $closurePtr ); |
|
87 | 87 | |
88 | 88 | $errorMsg = 'Variables bound to a closure via the use construct cannot use the same name as superglobals, $this, or a declared parameter since PHP 7.1. Found: %s'; |
89 | 89 | |
90 | - for ($i = ($nextNonEmpty + 1); $i < $tokens[$nextNonEmpty]['parenthesis_closer']; $i++) { |
|
91 | - if ($tokens[$i]['code'] !== \T_VARIABLE) { |
|
90 | + for ( $i = ( $nextNonEmpty + 1 ); $i < $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; $i++ ) { |
|
91 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE ) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | |
95 | - $variableName = $tokens[$i]['content']; |
|
95 | + $variableName = $tokens[ $i ][ 'content' ]; |
|
96 | 96 | |
97 | - if ($variableName === '$this') { |
|
98 | - $phpcsFile->addError($errorMsg, $i, 'FoundThis', array($variableName)); |
|
97 | + if ( $variableName === '$this' ) { |
|
98 | + $phpcsFile->addError( $errorMsg, $i, 'FoundThis', array( $variableName ) ); |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | - if (isset($this->superglobals[$variableName]) === true) { |
|
103 | - $phpcsFile->addError($errorMsg, $i, 'FoundSuperglobal', array($variableName)); |
|
102 | + if ( isset( $this->superglobals[ $variableName ] ) === true ) { |
|
103 | + $phpcsFile->addError( $errorMsg, $i, 'FoundSuperglobal', array( $variableName ) ); |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | |
107 | 107 | // Check whether it is one of the parameters declared by the closure. |
108 | - if (empty($closureParams) === false) { |
|
109 | - foreach ($closureParams as $param) { |
|
110 | - if ($param['name'] === $variableName) { |
|
111 | - $phpcsFile->addError($errorMsg, $i, 'FoundShadowParam', array($variableName)); |
|
108 | + if ( empty( $closureParams ) === false ) { |
|
109 | + foreach ( $closureParams as $param ) { |
|
110 | + if ( $param[ 'name' ] === $variableName ) { |
|
111 | + $phpcsFile->addError( $errorMsg, $i, 'FoundShadowParam', array( $variableName ) ); |
|
112 | 112 | continue 2; |
113 | 113 | } |
114 | 114 | } |
@@ -54,25 +54,25 @@ |
||
54 | 54 | * |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - public function process(File $phpcsFile, $stackPtr) |
|
57 | + public function process( File $phpcsFile, $stackPtr ) |
|
58 | 58 | { |
59 | - if ($this->supportsAbove('5.4') === false) { |
|
59 | + if ( $this->supportsAbove( '5.4' ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // Get all parameters from function signature. |
64 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
65 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
64 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
65 | + if ( empty( $parameters ) || \is_array( $parameters ) === false ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - foreach ($parameters as $param) { |
|
70 | - if (isset($this->superglobals[$param['name']]) === true) { |
|
69 | + foreach ( $parameters as $param ) { |
|
70 | + if ( isset( $this->superglobals[ $param[ 'name' ] ] ) === true ) { |
|
71 | 71 | $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4'; |
72 | - $errorCode = $this->stringToErrorCode(substr($param['name'], 1)) . 'Found'; |
|
73 | - $data = array($param['name']); |
|
72 | + $errorCode = $this->stringToErrorCode( substr( $param[ 'name' ], 1 ) ) . 'Found'; |
|
73 | + $data = array( $param[ 'name' ] ); |
|
74 | 74 | |
75 | - $phpcsFile->addError($error, $param['token'], $errorCode, $data); |
|
75 | + $phpcsFile->addError( $error, $param[ 'token' ], $errorCode, $data ); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
@@ -51,31 +51,31 @@ |
||
51 | 51 | * |
52 | 52 | * @return void |
53 | 53 | */ |
54 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | + public function process( File $phpcsFile, $stackPtr ) |
|
55 | 55 | { |
56 | - if ($this->supportsAbove('7.0') === false) { |
|
56 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | - $token = $tokens[$stackPtr]; |
|
61 | + $token = $tokens[ $stackPtr ]; |
|
62 | 62 | // Skip function without body. |
63 | - if (isset($token['scope_opener']) === false) { |
|
63 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Get all parameters from method signature. |
68 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
69 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
68 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
69 | + if ( empty( $parameters ) || \is_array( $parameters ) === false ) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $paramNames = array(); |
74 | - foreach ($parameters as $param) { |
|
75 | - $paramNames[] = strtolower($param['name']); |
|
74 | + foreach ( $parameters as $param ) { |
|
75 | + $paramNames[ ] = strtolower( $param[ 'name' ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | - if (\count($paramNames) !== \count(array_unique($paramNames))) { |
|
78 | + if ( \count( $paramNames ) !== \count( array_unique( $paramNames ) ) ) { |
|
79 | 79 | $phpcsFile->addError( |
80 | 80 | 'Functions can not have multiple parameters with the same name since PHP 7.0', |
81 | 81 | $stackPtr, |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function register() |
49 | 49 | { |
50 | - return array(\T_FUNCTION); |
|
50 | + return array( \T_FUNCTION ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - public function process(File $phpcsFile, $stackPtr) |
|
64 | + public function process( File $phpcsFile, $stackPtr ) |
|
65 | 65 | { |
66 | - if ($this->supportsBelow('7.3') === false) { |
|
66 | + if ( $this->supportsBelow( '7.3' ) === false ) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $tokens = $phpcsFile->getTokens(); |
71 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
71 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
72 | 72 | // Abstract function, interface function, live coding or parse error. |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
77 | - if (strtolower($functionName) !== '__tostring') { |
|
76 | + $functionName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
77 | + if ( strtolower( $functionName ) !== '__tostring' ) { |
|
78 | 78 | // Not the right function. |
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
82 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) === false ) { |
|
83 | 83 | // Function, not method. |
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | - $hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']); |
|
87 | + $hasThrow = $phpcsFile->findNext( \T_THROW, ( $tokens[ $stackPtr ][ 'scope_opener' ] + 1 ), $tokens[ $stackPtr ][ 'scope_closer' ] ); |
|
88 | 88 | |
89 | - if ($hasThrow === false) { |
|
89 | + if ( $hasThrow === false ) { |
|
90 | 90 | // No exception is being thrown. |
91 | 91 | return; |
92 | 92 | } |