@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $parameter_position = $this->phpcsFile->findNext( |
| 180 | 180 | Tokens::$emptyTokens, |
| 181 | - $parameter['start'], |
|
| 182 | - $parameter['end'] + 1, |
|
| 181 | + $parameter[ 'start' ], |
|
| 182 | + $parameter[ 'end' ] + 1, |
|
| 183 | 183 | true |
| 184 | 184 | ); |
| 185 | 185 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $matched_parameter = $this->strip_quotes( $this->tokens[ $parameter_position ]['content'] ); |
|
| 190 | + $matched_parameter = $this->strip_quotes( $this->tokens[ $parameter_position ][ 'content' ] ); |
|
| 191 | 191 | if ( ! isset( $parameter_args[ $matched_parameter ] ) ) { |
| 192 | 192 | return; |
| 193 | 193 | } |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | $message = 'The parameter value "%s" has been deprecated since WordPress version %s.'; |
| 196 | 196 | $data = array( |
| 197 | 197 | $matched_parameter, |
| 198 | - $parameter_args[ $matched_parameter ]['version'], |
|
| 198 | + $parameter_args[ $matched_parameter ][ 'version' ], |
|
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | - if ( ! empty( $parameter_args[ $matched_parameter ]['alt'] ) ) { |
|
| 201 | + if ( ! empty( $parameter_args[ $matched_parameter ][ 'alt' ] ) ) { |
|
| 202 | 202 | $message .= ' Use %s instead.'; |
| 203 | - $data[] = $parameter_args[ $matched_parameter ]['alt']; |
|
| 203 | + $data[ ] = $parameter_args[ $matched_parameter ][ 'alt' ]; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $is_error = version_compare( $parameter_args[ $matched_parameter ]['version'], $this->minimum_supported_version, '<' ); |
|
| 206 | + $is_error = version_compare( $parameter_args[ $matched_parameter ][ 'version' ], $this->minimum_supported_version, '<' ); |
|
| 207 | 207 | $this->addMessage( |
| 208 | 208 | $message, |
| 209 | 209 | $parameter_position, |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function process_token( $stackPtr ) { |
| 87 | 87 | $token = $this->tokens[ $stackPtr ]; |
| 88 | 88 | |
| 89 | - if ( 'cron_schedules' !== $this->strip_quotes( $token['content'] ) ) { |
|
| 89 | + if ( 'cron_schedules' !== $this->strip_quotes( $token[ 'content' ] ) ) { |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ( $stackPtr >= $callback['start'] ) { |
|
| 104 | + if ( $stackPtr >= $callback[ 'start' ] ) { |
|
| 105 | 105 | // "cron_schedules" found in the second parameter, not the first. |
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Detect callback function name. |
| 110 | - $callbackArrayPtr = $this->phpcsFile->findNext( Tokens::$emptyTokens, $callback['start'], ( $callback['end'] + 1 ), true ); |
|
| 110 | + $callbackArrayPtr = $this->phpcsFile->findNext( Tokens::$emptyTokens, $callback[ 'start' ], ( $callback[ 'end' ] + 1 ), true ); |
|
| 111 | 111 | |
| 112 | 112 | // If callback is array, get second element. |
| 113 | 113 | if ( false !== $callbackArrayPtr |
| 114 | - && ( \T_ARRAY === $this->tokens[ $callbackArrayPtr ]['code'] |
|
| 115 | - || \T_OPEN_SHORT_ARRAY === $this->tokens[ $callbackArrayPtr ]['code'] ) |
|
| 114 | + && ( \T_ARRAY === $this->tokens[ $callbackArrayPtr ][ 'code' ] |
|
| 115 | + || \T_OPEN_SHORT_ARRAY === $this->tokens[ $callbackArrayPtr ][ 'code' ] ) |
|
| 116 | 116 | ) { |
| 117 | 117 | $callback = $this->get_function_call_parameter( $callbackArrayPtr, 2 ); |
| 118 | 118 | |
@@ -125,27 +125,27 @@ discard block |
||
| 125 | 125 | unset( $functionPtr ); |
| 126 | 126 | |
| 127 | 127 | // Search for the function in tokens. |
| 128 | - $callbackFunctionPtr = $this->phpcsFile->findNext( array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING, \T_CLOSURE ), $callback['start'], ( $callback['end'] + 1 ) ); |
|
| 128 | + $callbackFunctionPtr = $this->phpcsFile->findNext( array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING, \T_CLOSURE ), $callback[ 'start' ], ( $callback[ 'end' ] + 1 ) ); |
|
| 129 | 129 | |
| 130 | 130 | if ( false === $callbackFunctionPtr ) { |
| 131 | 131 | $this->confused( $stackPtr ); |
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( \T_CLOSURE === $this->tokens[ $callbackFunctionPtr ]['code'] ) { |
|
| 135 | + if ( \T_CLOSURE === $this->tokens[ $callbackFunctionPtr ][ 'code' ] ) { |
|
| 136 | 136 | $functionPtr = $callbackFunctionPtr; |
| 137 | 137 | } else { |
| 138 | - $functionName = $this->strip_quotes( $this->tokens[ $callbackFunctionPtr ]['content'] ); |
|
| 138 | + $functionName = $this->strip_quotes( $this->tokens[ $callbackFunctionPtr ][ 'content' ] ); |
|
| 139 | 139 | |
| 140 | 140 | for ( $ptr = 0; $ptr < $this->phpcsFile->numTokens; $ptr++ ) { |
| 141 | - if ( \T_FUNCTION === $this->tokens[ $ptr ]['code'] ) { |
|
| 141 | + if ( \T_FUNCTION === $this->tokens[ $ptr ][ 'code' ] ) { |
|
| 142 | 142 | $foundName = $this->phpcsFile->getDeclarationName( $ptr ); |
| 143 | 143 | if ( $foundName === $functionName ) { |
| 144 | 144 | $functionPtr = $ptr; |
| 145 | 145 | break; |
| 146 | - } elseif ( isset( $this->tokens[ $ptr ]['scope_closer'] ) ) { |
|
| 146 | + } elseif ( isset( $this->tokens[ $ptr ][ 'scope_closer' ] ) ) { |
|
| 147 | 147 | // Skip to the end of the function definition. |
| 148 | - $ptr = $this->tokens[ $ptr ]['scope_closer']; |
|
| 148 | + $ptr = $this->tokens[ $ptr ][ 'scope_closer' ]; |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( ! isset( $this->tokens[ $functionPtr ]['scope_opener'], $this->tokens[ $functionPtr ]['scope_closer'] ) ) { |
|
| 159 | + if ( ! isset( $this->tokens[ $functionPtr ][ 'scope_opener' ], $this->tokens[ $functionPtr ][ 'scope_closer' ] ) ) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $opening = $this->tokens[ $functionPtr ]['scope_opener']; |
|
| 164 | - $closing = $this->tokens[ $functionPtr ]['scope_closer']; |
|
| 163 | + $opening = $this->tokens[ $functionPtr ][ 'scope_opener' ]; |
|
| 164 | + $closing = $this->tokens[ $functionPtr ][ 'scope_closer' ]; |
|
| 165 | 165 | for ( $i = $opening; $i <= $closing; $i++ ) { |
| 166 | 166 | |
| 167 | - if ( \in_array( $this->tokens[ $i ]['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 168 | - if ( 'interval' === $this->strip_quotes( $this->tokens[ $i ]['content'] ) ) { |
|
| 167 | + if ( \in_array( $this->tokens[ $i ][ 'code' ], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 168 | + if ( 'interval' === $this->strip_quotes( $this->tokens[ $i ][ 'content' ] ) ) { |
|
| 169 | 169 | $operator = $this->phpcsFile->findNext( \T_DOUBLE_ARROW, $i, null, false, null, true ); |
| 170 | 170 | if ( false === $operator ) { |
| 171 | 171 | $this->confused( $stackPtr ); |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | $valueEnd = $this->phpcsFile->findNext( array( \T_COMMA, \T_CLOSE_PARENTHESIS ), ( $valueStart + 1 ) ); |
| 177 | 177 | $value = ''; |
| 178 | 178 | for ( $j = $valueStart; $j < $valueEnd; $j++ ) { |
| 179 | - if ( isset( Tokens::$emptyTokens[ $this->tokens[ $j ]['code'] ] ) ) { |
|
| 179 | + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $j ][ 'code' ] ] ) ) { |
|
| 180 | 180 | continue; |
| 181 | 181 | } |
| 182 | - $value .= $this->tokens[ $j ]['content']; |
|
| 182 | + $value .= $this->tokens[ $j ][ 'content' ]; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | if ( is_numeric( $value ) ) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $this->min_interval = (int) $this->min_interval; |
|
| 205 | + $this->min_interval = (int)$this->min_interval; |
|
| 206 | 206 | |
| 207 | 207 | if ( isset( $interval ) && $interval < $this->min_interval ) { |
| 208 | 208 | $minutes = round( ( $this->min_interval / 60 ), 1 ); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | public function process_token( $stackPtr ) { |
| 45 | 45 | $token = $this->tokens[ $stackPtr ]; |
| 46 | 46 | |
| 47 | - if ( preg_match( '# rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token['content'] ) > 0 ) { |
|
| 47 | + if ( preg_match( '# rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token[ 'content' ] ) > 0 ) { |
|
| 48 | 48 | $this->phpcsFile->addError( |
| 49 | 49 | 'Stylesheets must be registered/enqueued via wp_enqueue_style', |
| 50 | 50 | $stackPtr, |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( preg_match( '#<script[^>]*(?<=src=)#', $token['content'] ) > 0 ) { |
|
| 55 | + if ( preg_match( '#<script[^>]*(?<=src=)#', $token[ 'content' ] ) > 0 ) { |
|
| 56 | 56 | $this->phpcsFile->addError( |
| 57 | 57 | 'Scripts must be registered/enqueued via wp_enqueue_script', |
| 58 | 58 | $stackPtr, |
@@ -1382,18 +1382,18 @@ |
||
| 1382 | 1382 | $message = '%s() has been deprecated since WordPress version %s.'; |
| 1383 | 1383 | $data = array( |
| 1384 | 1384 | $matched_content, |
| 1385 | - $this->deprecated_functions[ $function_name ]['version'], |
|
| 1385 | + $this->deprecated_functions[ $function_name ][ 'version' ], |
|
| 1386 | 1386 | ); |
| 1387 | 1387 | |
| 1388 | - if ( ! empty( $this->deprecated_functions[ $function_name ]['alt'] ) ) { |
|
| 1388 | + if ( ! empty( $this->deprecated_functions[ $function_name ][ 'alt' ] ) ) { |
|
| 1389 | 1389 | $message .= ' Use %s instead.'; |
| 1390 | - $data[] = $this->deprecated_functions[ $function_name ]['alt']; |
|
| 1390 | + $data[ ] = $this->deprecated_functions[ $function_name ][ 'alt' ]; |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | $this->addMessage( |
| 1394 | 1394 | $message, |
| 1395 | 1395 | $stackPtr, |
| 1396 | - ( version_compare( $this->deprecated_functions[ $function_name ]['version'], $this->minimum_supported_version, '<' ) ), |
|
| 1396 | + ( version_compare( $this->deprecated_functions[ $function_name ][ 'version' ], $this->minimum_supported_version, '<' ) ), |
|
| 1397 | 1397 | $this->string_to_errorcode( $matched_content . 'Found' ), |
| 1398 | 1398 | $data |
| 1399 | 1399 | ); |
@@ -126,24 +126,24 @@ discard block |
||
| 126 | 126 | * The return values skip to the end of the array. |
| 127 | 127 | * This prevents the sniff "hanging" on very long configuration arrays. |
| 128 | 128 | */ |
| 129 | - if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) { |
|
| 130 | - return $this->tokens[ $stackPtr ]['bracket_closer']; |
|
| 131 | - } elseif ( \T_ARRAY === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ $stackPtr ]['parenthesis_closer'] ) ) { |
|
| 132 | - return $this->tokens[ $stackPtr ]['parenthesis_closer']; |
|
| 129 | + if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] && isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
| 130 | + return $this->tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
| 131 | + } elseif ( \T_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] && isset( $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] ) ) { |
|
| 132 | + return $this->tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /* |
| 136 | 136 | * Deal with misspellings in class/interface/trait names. |
| 137 | 137 | * These are not auto-fixable, but need the attention of a developer. |
| 138 | 138 | */ |
| 139 | - if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { |
|
| 139 | + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) { |
|
| 140 | 140 | $classname = $this->phpcsFile->getDeclarationName( $stackPtr ); |
| 141 | 141 | if ( empty( $classname ) ) { |
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | if ( preg_match_all( self::WP_CLASSNAME_REGEX, $classname, $matches, \PREG_PATTERN_ORDER ) > 0 ) { |
| 146 | - $mispelled = $this->retrieve_misspellings( $matches[1] ); |
|
| 146 | + $mispelled = $this->retrieve_misspellings( $matches[ 1 ] ); |
|
| 147 | 147 | |
| 148 | 148 | if ( ! empty( $mispelled ) ) { |
| 149 | 149 | $this->phpcsFile->addWarning( |
@@ -163,14 +163,14 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | |
| 165 | 165 | // Ignore content of docblock @link tags. |
| 166 | - if ( \T_DOC_COMMENT_STRING === $this->tokens[ $stackPtr ]['code'] |
|
| 167 | - || \T_DOC_COMMENT === $this->tokens[ $stackPtr ]['code'] |
|
| 166 | + if ( \T_DOC_COMMENT_STRING === $this->tokens[ $stackPtr ][ 'code' ] |
|
| 167 | + || \T_DOC_COMMENT === $this->tokens[ $stackPtr ][ 'code' ] |
|
| 168 | 168 | ) { |
| 169 | 169 | |
| 170 | 170 | $comment_start = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_OPEN_TAG, ( $stackPtr - 1 ) ); |
| 171 | 171 | if ( false !== $comment_start ) { |
| 172 | 172 | $comment_tag = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_TAG, ( $stackPtr - 1 ), $comment_start ); |
| 173 | - if ( false !== $comment_tag && '@link' === $this->tokens[ $comment_tag ]['content'] ) { |
|
| 173 | + if ( false !== $comment_tag && '@link' === $this->tokens[ $comment_tag ][ 'content' ] ) { |
|
| 174 | 174 | // @link tag, so ignore. |
| 175 | 175 | return; |
| 176 | 176 | } |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Ignore any text strings which are array keys `$var['key']` as this is a false positive in 80% of all cases. |
| 181 | - if ( \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
| 181 | + if ( \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
| 182 | 182 | $prevToken = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
| 183 | - if ( false !== $prevToken && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $prevToken ]['code'] ) { |
|
| 183 | + if ( false !== $prevToken && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $prevToken ][ 'code' ] ) { |
|
| 184 | 184 | $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
| 185 | - if ( false !== $nextToken && \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $nextToken ]['code'] ) { |
|
| 185 | + if ( false !== $nextToken && \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $nextToken ][ 'code' ] ) { |
|
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -202,44 +202,44 @@ discard block |
||
| 202 | 202 | \T_OPEN_CURLY_BRACKET, |
| 203 | 203 | ); |
| 204 | 204 | $maybe_const = $this->phpcsFile->findPrevious( $stop_points, ( $stackPtr - 1 ) ); |
| 205 | - if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ]['code'] ) { |
|
| 205 | + if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ][ 'code' ] ) { |
|
| 206 | 206 | return; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - $content = $this->tokens[ $stackPtr ]['content']; |
|
| 209 | + $content = $this->tokens[ $stackPtr ][ 'content' ]; |
|
| 210 | 210 | |
| 211 | 211 | if ( preg_match_all( self::WP_REGEX, $content, $matches, ( \PREG_PATTERN_ORDER | \PREG_OFFSET_CAPTURE ) ) > 0 ) { |
| 212 | 212 | /* |
| 213 | 213 | * Prevent some typical false positives. |
| 214 | 214 | */ |
| 215 | - if ( isset( $this->text_and_comment_tokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { |
|
| 215 | + if ( isset( $this->text_and_comment_tokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) { |
|
| 216 | 216 | $offset = 0; |
| 217 | - foreach ( $matches[1] as $key => $match_data ) { |
|
| 218 | - $next_offset = ( $match_data[1] + \strlen( $match_data[0] ) ); |
|
| 217 | + foreach ( $matches[ 1 ] as $key => $match_data ) { |
|
| 218 | + $next_offset = ( $match_data[ 1 ] + \strlen( $match_data[ 0 ] ) ); |
|
| 219 | 219 | |
| 220 | 220 | // Prevent matches on part of a URL. |
| 221 | - if ( preg_match( '`http[s]?://[^\s<>\'"()]*' . preg_quote( $match_data[0], '`' ) . '`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 222 | - unset( $matches[1][ $key ] ); |
|
| 223 | - } elseif ( preg_match( '`[a-z]+=(["\'])' . preg_quote( $match_data[0], '`' ) . '\1`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 221 | + if ( preg_match( '`http[s]?://[^\s<>\'"()]*' . preg_quote( $match_data[ 0 ], '`' ) . '`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 222 | + unset( $matches[ 1 ][ $key ] ); |
|
| 223 | + } elseif ( preg_match( '`[a-z]+=(["\'])' . preg_quote( $match_data[ 0 ], '`' ) . '\1`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 224 | 224 | // Prevent matches on html attributes like: `value="wordpress"`. |
| 225 | - unset( $matches[1][ $key ] ); |
|
| 226 | - } elseif ( preg_match( '`\\\\\'' . preg_quote( $match_data[0], '`' ) . '\\\\\'`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 225 | + unset( $matches[ 1 ][ $key ] ); |
|
| 226 | + } elseif ( preg_match( '`\\\\\'' . preg_quote( $match_data[ 0 ], '`' ) . '\\\\\'`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 227 | 227 | // Prevent matches on xpath queries and such: `\'wordpress\'`. |
| 228 | - unset( $matches[1][ $key ] ); |
|
| 229 | - } elseif ( preg_match( '`(?:\?|&|&)[a-z0-9_]+=' . preg_quote( $match_data[0], '`' ) . '(?:&|$)`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 228 | + unset( $matches[ 1 ][ $key ] ); |
|
| 229 | + } elseif ( preg_match( '`(?:\?|&|&)[a-z0-9_]+=' . preg_quote( $match_data[ 0 ], '`' ) . '(?:&|$)`', $content, $discard, 0, $offset ) === 1 ) { |
|
| 230 | 230 | // Prevent matches on url query strings: `?something=wordpress`. |
| 231 | - unset( $matches[1][ $key ] ); |
|
| 231 | + unset( $matches[ 1 ][ $key ] ); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $offset = $next_offset; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( empty( $matches[1] ) ) { |
|
| 237 | + if ( empty( $matches[ 1 ] ) ) { |
|
| 238 | 238 | return; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - $mispelled = $this->retrieve_misspellings( $matches[1] ); |
|
| 242 | + $mispelled = $this->retrieve_misspellings( $matches[ 1 ] ); |
|
| 243 | 243 | |
| 244 | 244 | if ( empty( $mispelled ) ) { |
| 245 | 245 | return; |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | if ( true === $fix ) { |
| 259 | 259 | // Apply fixes based on offset to ensure we don't replace false positives. |
| 260 | 260 | $replacement = $content; |
| 261 | - foreach ( $matches[1] as $match ) { |
|
| 262 | - $replacement = substr_replace( $replacement, 'WordPress', $match[1], \strlen( $match[0] ) ); |
|
| 261 | + foreach ( $matches[ 1 ] as $match ) { |
|
| 262 | + $replacement = substr_replace( $replacement, 'WordPress', $match[ 1 ], \strlen( $match[ 0 ] ) ); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $this->phpcsFile->fixer->replaceToken( $stackPtr, $replacement ); |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | foreach ( $match_stack as $match ) { |
| 279 | 279 | // Deal with multi-dimensional arrays when capturing offset. |
| 280 | 280 | if ( \is_array( $match ) ) { |
| 281 | - $match = $match[0]; |
|
| 281 | + $match = $match[ 0 ]; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | if ( 'WordPress' !== $match ) { |
| 285 | - $mispelled[] = $match; |
|
| 285 | + $mispelled[ ] = $match; |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
@@ -270,7 +270,7 @@ |
||
| 270 | 270 | /** |
| 271 | 271 | * Retrieve a list of misspellings based on an array of matched variations on the target word. |
| 272 | 272 | * |
| 273 | - * @param array $match_stack Array of matched variations of the target word. |
|
| 273 | + * @param string[] $match_stack Array of matched variations of the target word. |
|
| 274 | 274 | * @return array Array containing only the misspelled variants. |
| 275 | 275 | */ |
| 276 | 276 | protected function retrieve_misspellings( $match_stack ) { |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | $token = $this->tokens[ $stackPtr ]; |
| 143 | 143 | |
| 144 | - if ( \T_CLOSE_SQUARE_BRACKET === $token['code'] ) { |
|
| 144 | + if ( \T_CLOSE_SQUARE_BRACKET === $token[ 'code' ] ) { |
|
| 145 | 145 | $equal = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
| 146 | - if ( \T_EQUAL !== $this->tokens[ $equal ]['code'] ) { |
|
| 146 | + if ( \T_EQUAL !== $this->tokens[ $equal ][ 'code' ] ) { |
|
| 147 | 147 | return; // This is not an assignment! |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -156,28 +156,28 @@ discard block |
||
| 156 | 156 | * $foo = array( 'bar' => 'taz' ); |
| 157 | 157 | * $foo['bar'] = $taz; |
| 158 | 158 | */ |
| 159 | - if ( \in_array( $token['code'], array( \T_CLOSE_SQUARE_BRACKET, \T_DOUBLE_ARROW ), true ) ) { |
|
| 159 | + if ( \in_array( $token[ 'code' ], array( \T_CLOSE_SQUARE_BRACKET, \T_DOUBLE_ARROW ), true ) ) { |
|
| 160 | 160 | $operator = $stackPtr; // T_DOUBLE_ARROW. |
| 161 | - if ( \T_CLOSE_SQUARE_BRACKET === $token['code'] ) { |
|
| 161 | + if ( \T_CLOSE_SQUARE_BRACKET === $token[ 'code' ] ) { |
|
| 162 | 162 | $operator = $this->phpcsFile->findNext( \T_EQUAL, ( $stackPtr + 1 ) ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $keyIdx = $this->phpcsFile->findPrevious( array( \T_WHITESPACE, \T_CLOSE_SQUARE_BRACKET ), ( $operator - 1 ), null, true ); |
| 166 | - if ( ! is_numeric( $this->tokens[ $keyIdx ]['content'] ) ) { |
|
| 167 | - $key = $this->strip_quotes( $this->tokens[ $keyIdx ]['content'] ); |
|
| 166 | + if ( ! is_numeric( $this->tokens[ $keyIdx ][ 'content' ] ) ) { |
|
| 167 | + $key = $this->strip_quotes( $this->tokens[ $keyIdx ][ 'content' ] ); |
|
| 168 | 168 | $valStart = $this->phpcsFile->findNext( array( \T_WHITESPACE ), ( $operator + 1 ), null, true ); |
| 169 | 169 | $valEnd = $this->phpcsFile->findNext( array( \T_COMMA, \T_SEMICOLON ), ( $valStart + 1 ), null, false, null, true ); |
| 170 | 170 | $val = $this->phpcsFile->getTokensAsString( $valStart, ( $valEnd - $valStart ) ); |
| 171 | 171 | $val = $this->strip_quotes( $val ); |
| 172 | - $inst[ $key ][] = array( $val, $token['line'] ); |
|
| 172 | + $inst[ $key ][ ] = array( $val, $token[ 'line' ] ); |
|
| 173 | 173 | } |
| 174 | - } elseif ( \in_array( $token['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 174 | + } elseif ( \in_array( $token[ 'code' ], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 175 | 175 | // $foo = 'bar=taz&other=thing'; |
| 176 | - if ( preg_match_all( '#(?:^|&)([a-z_]+)=([^&]*)#i', $this->strip_quotes( $token['content'] ), $matches ) <= 0 ) { |
|
| 176 | + if ( preg_match_all( '#(?:^|&)([a-z_]+)=([^&]*)#i', $this->strip_quotes( $token[ 'content' ] ), $matches ) <= 0 ) { |
|
| 177 | 177 | return; // No assignments here, nothing to check. |
| 178 | 178 | } |
| 179 | - foreach ( $matches[1] as $i => $_k ) { |
|
| 180 | - $inst[ $_k ][] = array( $matches[2][ $i ], $token['line'] ); |
|
| 179 | + foreach ( $matches[ 1 ] as $i => $_k ) { |
|
| 180 | + $inst[ $_k ][ ] = array( $matches[ 2 ][ $i ], $token[ 'line' ] ); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | continue; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $callback = ( isset( $group['callback'] ) && is_callable( $group['callback'] ) ) ? $group['callback'] : array( $this, 'callback' ); |
|
| 194 | + $callback = ( isset( $group[ 'callback' ] ) && is_callable( $group[ 'callback' ] ) ) ? $group[ 'callback' ] : array( $this, 'callback' ); |
|
| 195 | 195 | |
| 196 | 196 | foreach ( $inst as $key => $assignments ) { |
| 197 | 197 | foreach ( $assignments as $occurance ) { |
| 198 | 198 | list( $val, $line ) = $occurance; |
| 199 | 199 | |
| 200 | - if ( ! \in_array( $key, $group['keys'], true ) ) { |
|
| 200 | + if ( ! \in_array( $key, $group[ 'keys' ], true ) ) { |
|
| 201 | 201 | continue; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | if ( ! isset( $output ) || false === $output ) { |
| 207 | 207 | continue; |
| 208 | 208 | } elseif ( true === $output ) { |
| 209 | - $message = $group['message']; |
|
| 209 | + $message = $group[ 'message' ]; |
|
| 210 | 210 | } else { |
| 211 | 211 | $message = $output; |
| 212 | 212 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $this->addMessage( |
| 215 | 215 | $message, |
| 216 | 216 | $stackPtr, |
| 217 | - ( 'error' === $group['type'] ), |
|
| 217 | + ( 'error' === $group[ 'type' ] ), |
|
| 218 | 218 | $this->string_to_errorcode( $groupName . '_' . $key ), |
| 219 | 219 | array( $key, $val ) |
| 220 | 220 | ); |
@@ -22,111 +22,111 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Handle the retrieval of relevant information and - if necessary - throwing of an |
|
| 27 | - * error/warning for an item. |
|
| 28 | - * |
|
| 29 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 30 | - * @param int $stackPtr The position of the relevant token in |
|
| 31 | - * the stack. |
|
| 32 | - * @param array $itemInfo Base information about the item. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) |
|
| 37 | - { |
|
| 38 | - $itemArray = $this->getItemArray($itemInfo); |
|
| 39 | - $errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
|
| 40 | - |
|
| 41 | - if ($this->shouldThrowError($errorInfo) === true) { |
|
| 42 | - $this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Determine whether an error/warning should be thrown for an item based on collected information. |
|
| 49 | - * |
|
| 50 | - * @param array $errorInfo Detail information about an item. |
|
| 51 | - * |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - abstract protected function shouldThrowError(array $errorInfo); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
| 59 | - * |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - protected function getNonVersionArrayKeys() |
|
| 63 | - { |
|
| 64 | - return array(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Retrieve a subset of an item array containing only the array keys which |
|
| 70 | - * contain PHP version information. |
|
| 71 | - * |
|
| 72 | - * @param array $itemArray Version and other information about an item. |
|
| 73 | - * |
|
| 74 | - * @return array Array with only the version information. |
|
| 75 | - */ |
|
| 76 | - protected function getVersionArray(array $itemArray) |
|
| 77 | - { |
|
| 78 | - return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Get the item name to be used for the creation of the error code and in the error message. |
|
| 84 | - * |
|
| 85 | - * @param array $itemInfo Base information about the item. |
|
| 86 | - * @param array $errorInfo Detail information about an item. |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
| 91 | - { |
|
| 92 | - return $itemInfo['name']; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Get the error message template for a specific sniff. |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - abstract protected function getErrorMsgTemplate(); |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
| 106 | - * |
|
| 107 | - * @param string $error The error message which was created. |
|
| 108 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
| 109 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
| 114 | - { |
|
| 115 | - return $error; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
| 121 | - * |
|
| 122 | - * @param array $data The error data array which was created. |
|
| 123 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
| 124 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
| 129 | - { |
|
| 130 | - return $data; |
|
| 131 | - } |
|
| 25 | + /** |
|
| 26 | + * Handle the retrieval of relevant information and - if necessary - throwing of an |
|
| 27 | + * error/warning for an item. |
|
| 28 | + * |
|
| 29 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 30 | + * @param int $stackPtr The position of the relevant token in |
|
| 31 | + * the stack. |
|
| 32 | + * @param array $itemInfo Base information about the item. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) |
|
| 37 | + { |
|
| 38 | + $itemArray = $this->getItemArray($itemInfo); |
|
| 39 | + $errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
|
| 40 | + |
|
| 41 | + if ($this->shouldThrowError($errorInfo) === true) { |
|
| 42 | + $this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Determine whether an error/warning should be thrown for an item based on collected information. |
|
| 49 | + * |
|
| 50 | + * @param array $errorInfo Detail information about an item. |
|
| 51 | + * |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + abstract protected function shouldThrowError(array $errorInfo); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
| 59 | + * |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + protected function getNonVersionArrayKeys() |
|
| 63 | + { |
|
| 64 | + return array(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Retrieve a subset of an item array containing only the array keys which |
|
| 70 | + * contain PHP version information. |
|
| 71 | + * |
|
| 72 | + * @param array $itemArray Version and other information about an item. |
|
| 73 | + * |
|
| 74 | + * @return array Array with only the version information. |
|
| 75 | + */ |
|
| 76 | + protected function getVersionArray(array $itemArray) |
|
| 77 | + { |
|
| 78 | + return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Get the item name to be used for the creation of the error code and in the error message. |
|
| 84 | + * |
|
| 85 | + * @param array $itemInfo Base information about the item. |
|
| 86 | + * @param array $errorInfo Detail information about an item. |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + protected function getItemName(array $itemInfo, array $errorInfo) |
|
| 91 | + { |
|
| 92 | + return $itemInfo['name']; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Get the error message template for a specific sniff. |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + abstract protected function getErrorMsgTemplate(); |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
| 106 | + * |
|
| 107 | + * @param string $error The error message which was created. |
|
| 108 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
| 109 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
| 114 | + { |
|
| 115 | + return $error; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Allow for concrete child classes to filter the error data before it's passed to PHPCS. |
|
| 121 | + * |
|
| 122 | + * @param array $data The error data array which was created. |
|
| 123 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
| 124 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
| 129 | + { |
|
| 130 | + return $data; |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) |
|
| 36 | + public function handleFeature( File $phpcsFile, $stackPtr, array $itemInfo ) |
|
| 37 | 37 | { |
| 38 | - $itemArray = $this->getItemArray($itemInfo); |
|
| 39 | - $errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
|
| 38 | + $itemArray = $this->getItemArray( $itemInfo ); |
|
| 39 | + $errorInfo = $this->getErrorInfo( $itemArray, $itemInfo ); |
|
| 40 | 40 | |
| 41 | - if ($this->shouldThrowError($errorInfo) === true) { |
|
| 42 | - $this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
|
| 41 | + if ( $this->shouldThrowError( $errorInfo ) === true ) { |
|
| 42 | + $this->addError( $phpcsFile, $stackPtr, $itemInfo, $errorInfo ); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return bool |
| 53 | 53 | */ |
| 54 | - abstract protected function shouldThrowError(array $errorInfo); |
|
| 54 | + abstract protected function shouldThrowError( array $errorInfo ); |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return array Array with only the version information. |
| 75 | 75 | */ |
| 76 | - protected function getVersionArray(array $itemArray) |
|
| 76 | + protected function getVersionArray( array $itemArray ) |
|
| 77 | 77 | { |
| 78 | - return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
|
| 78 | + return array_diff_key( $itemArray, array_flip( $this->getNonVersionArrayKeys() ) ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
| 90 | + protected function getItemName( array $itemInfo, array $errorInfo ) |
|
| 91 | 91 | { |
| 92 | - return $itemInfo['name']; |
|
| 92 | + return $itemInfo[ 'name' ]; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
| 113 | + protected function filterErrorMsg( $error, array $itemInfo, array $errorInfo ) |
|
| 114 | 114 | { |
| 115 | 115 | return $error; |
| 116 | 116 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return array |
| 127 | 127 | */ |
| 128 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
| 128 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
| 129 | 129 | { |
| 130 | 130 | return $data; |
| 131 | 131 | } |
@@ -18,8 +18,7 @@ discard block |
||
| 18 | 18 | * @package PHPCompatibility |
| 19 | 19 | * @author Juliette Reinders Folmer <[email protected]> |
| 20 | 20 | */ |
| 21 | -abstract class AbstractComplexVersionSniff extends Sniff implements ComplexVersionInterface |
|
| 22 | -{ |
|
| 21 | +abstract class AbstractComplexVersionSniff extends Sniff implements ComplexVersionInterface { |
|
| 23 | 22 | |
| 24 | 23 | |
| 25 | 24 | /** |
@@ -33,8 +32,7 @@ discard block |
||
| 33 | 32 | * |
| 34 | 33 | * @return void |
| 35 | 34 | */ |
| 36 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) |
|
| 37 | - { |
|
| 35 | + public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) { |
|
| 38 | 36 | $itemArray = $this->getItemArray($itemInfo); |
| 39 | 37 | $errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
| 40 | 38 | |
@@ -59,8 +57,7 @@ discard block |
||
| 59 | 57 | * |
| 60 | 58 | * @return array |
| 61 | 59 | */ |
| 62 | - protected function getNonVersionArrayKeys() |
|
| 63 | - { |
|
| 60 | + protected function getNonVersionArrayKeys() { |
|
| 64 | 61 | return array(); |
| 65 | 62 | } |
| 66 | 63 | |
@@ -73,8 +70,7 @@ discard block |
||
| 73 | 70 | * |
| 74 | 71 | * @return array Array with only the version information. |
| 75 | 72 | */ |
| 76 | - protected function getVersionArray(array $itemArray) |
|
| 77 | - { |
|
| 73 | + protected function getVersionArray(array $itemArray) { |
|
| 78 | 74 | return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
| 79 | 75 | } |
| 80 | 76 | |
@@ -87,8 +83,7 @@ discard block |
||
| 87 | 83 | * |
| 88 | 84 | * @return string |
| 89 | 85 | */ |
| 90 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
| 91 | - { |
|
| 86 | + protected function getItemName(array $itemInfo, array $errorInfo) { |
|
| 92 | 87 | return $itemInfo['name']; |
| 93 | 88 | } |
| 94 | 89 | |
@@ -110,8 +105,7 @@ discard block |
||
| 110 | 105 | * |
| 111 | 106 | * @return string |
| 112 | 107 | */ |
| 113 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
| 114 | - { |
|
| 108 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) { |
|
| 115 | 109 | return $error; |
| 116 | 110 | } |
| 117 | 111 | |
@@ -125,8 +119,7 @@ discard block |
||
| 125 | 119 | * |
| 126 | 120 | * @return array |
| 127 | 121 | */ |
| 128 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
| 129 | - { |
|
| 122 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) { |
|
| 130 | 123 | return $data; |
| 131 | 124 | } |
| 132 | 125 | } |
@@ -22,87 +22,87 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Determine whether an error/warning should be thrown for an item based on collected information. |
|
| 27 | - * |
|
| 28 | - * @param array $errorInfo Detail information about an item. |
|
| 29 | - * |
|
| 30 | - * @return bool |
|
| 31 | - */ |
|
| 32 | - protected function shouldThrowError(array $errorInfo) |
|
| 33 | - { |
|
| 34 | - return ($errorInfo['not_in_version'] !== ''); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
| 40 | - * |
|
| 41 | - * @param array $itemArray Version and other information about the item. |
|
| 42 | - * @param array $itemInfo Base information about the item. |
|
| 43 | - * |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
| 47 | - { |
|
| 48 | - $errorInfo = array( |
|
| 49 | - 'not_in_version' => '', |
|
| 50 | - 'error' => true, |
|
| 51 | - ); |
|
| 52 | - |
|
| 53 | - $versionArray = $this->getVersionArray($itemArray); |
|
| 54 | - |
|
| 55 | - if (empty($versionArray) === false) { |
|
| 56 | - foreach ($versionArray as $version => $present) { |
|
| 57 | - if ($errorInfo['not_in_version'] === '' && $present === false |
|
| 58 | - && $this->supportsBelow($version) === true |
|
| 59 | - ) { |
|
| 60 | - $errorInfo['not_in_version'] = $version; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $errorInfo; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get the error message template for this sniff. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - protected function getErrorMsgTemplate() |
|
| 75 | - { |
|
| 76 | - return '%s is not present in PHP version %s or earlier'; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Generates the error or warning for this item. |
|
| 82 | - * |
|
| 83 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 84 | - * @param int $stackPtr The position of the relevant token in |
|
| 85 | - * the stack. |
|
| 86 | - * @param array $itemInfo Base information about the item. |
|
| 87 | - * @param array $errorInfo Array with detail (version) information |
|
| 88 | - * relevant to the item. |
|
| 89 | - * |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
| 93 | - { |
|
| 94 | - $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
| 95 | - $error = $this->getErrorMsgTemplate(); |
|
| 96 | - |
|
| 97 | - $errorCode = $this->stringToErrorCode($itemName) . 'Found'; |
|
| 98 | - $data = array( |
|
| 99 | - $itemName, |
|
| 100 | - $errorInfo['not_in_version'], |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
| 104 | - $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
| 105 | - |
|
| 106 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
| 107 | - } |
|
| 25 | + /** |
|
| 26 | + * Determine whether an error/warning should be thrown for an item based on collected information. |
|
| 27 | + * |
|
| 28 | + * @param array $errorInfo Detail information about an item. |
|
| 29 | + * |
|
| 30 | + * @return bool |
|
| 31 | + */ |
|
| 32 | + protected function shouldThrowError(array $errorInfo) |
|
| 33 | + { |
|
| 34 | + return ($errorInfo['not_in_version'] !== ''); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
| 40 | + * |
|
| 41 | + * @param array $itemArray Version and other information about the item. |
|
| 42 | + * @param array $itemInfo Base information about the item. |
|
| 43 | + * |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
| 47 | + { |
|
| 48 | + $errorInfo = array( |
|
| 49 | + 'not_in_version' => '', |
|
| 50 | + 'error' => true, |
|
| 51 | + ); |
|
| 52 | + |
|
| 53 | + $versionArray = $this->getVersionArray($itemArray); |
|
| 54 | + |
|
| 55 | + if (empty($versionArray) === false) { |
|
| 56 | + foreach ($versionArray as $version => $present) { |
|
| 57 | + if ($errorInfo['not_in_version'] === '' && $present === false |
|
| 58 | + && $this->supportsBelow($version) === true |
|
| 59 | + ) { |
|
| 60 | + $errorInfo['not_in_version'] = $version; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $errorInfo; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get the error message template for this sniff. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + protected function getErrorMsgTemplate() |
|
| 75 | + { |
|
| 76 | + return '%s is not present in PHP version %s or earlier'; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Generates the error or warning for this item. |
|
| 82 | + * |
|
| 83 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 84 | + * @param int $stackPtr The position of the relevant token in |
|
| 85 | + * the stack. |
|
| 86 | + * @param array $itemInfo Base information about the item. |
|
| 87 | + * @param array $errorInfo Array with detail (version) information |
|
| 88 | + * relevant to the item. |
|
| 89 | + * |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
| 93 | + { |
|
| 94 | + $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
| 95 | + $error = $this->getErrorMsgTemplate(); |
|
| 96 | + |
|
| 97 | + $errorCode = $this->stringToErrorCode($itemName) . 'Found'; |
|
| 98 | + $data = array( |
|
| 99 | + $itemName, |
|
| 100 | + $errorInfo['not_in_version'], |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
| 104 | + $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
| 105 | + |
|
| 106 | + $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @return bool |
| 31 | 31 | */ |
| 32 | - protected function shouldThrowError(array $errorInfo) |
|
| 32 | + protected function shouldThrowError( array $errorInfo ) |
|
| 33 | 33 | { |
| 34 | - return ($errorInfo['not_in_version'] !== ''); |
|
| 34 | + return ( $errorInfo[ 'not_in_version' ] !== '' ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
@@ -43,21 +43,21 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
| 46 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
| 47 | 47 | { |
| 48 | 48 | $errorInfo = array( |
| 49 | 49 | 'not_in_version' => '', |
| 50 | 50 | 'error' => true, |
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | - $versionArray = $this->getVersionArray($itemArray); |
|
| 53 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
| 54 | 54 | |
| 55 | - if (empty($versionArray) === false) { |
|
| 56 | - foreach ($versionArray as $version => $present) { |
|
| 57 | - if ($errorInfo['not_in_version'] === '' && $present === false |
|
| 58 | - && $this->supportsBelow($version) === true |
|
| 55 | + if ( empty( $versionArray ) === false ) { |
|
| 56 | + foreach ( $versionArray as $version => $present ) { |
|
| 57 | + if ( $errorInfo[ 'not_in_version' ] === '' && $present === false |
|
| 58 | + && $this->supportsBelow( $version ) === true |
|
| 59 | 59 | ) { |
| 60 | - $errorInfo['not_in_version'] = $version; |
|
| 60 | + $errorInfo[ 'not_in_version' ] = $version; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -89,20 +89,20 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
| 92 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
| 93 | 93 | { |
| 94 | - $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
| 94 | + $itemName = $this->getItemName( $itemInfo, $errorInfo ); |
|
| 95 | 95 | $error = $this->getErrorMsgTemplate(); |
| 96 | 96 | |
| 97 | - $errorCode = $this->stringToErrorCode($itemName) . 'Found'; |
|
| 97 | + $errorCode = $this->stringToErrorCode( $itemName ) . 'Found'; |
|
| 98 | 98 | $data = array( |
| 99 | 99 | $itemName, |
| 100 | - $errorInfo['not_in_version'], |
|
| 100 | + $errorInfo[ 'not_in_version' ], |
|
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | - $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
| 104 | - $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
| 103 | + $error = $this->filterErrorMsg( $error, $itemInfo, $errorInfo ); |
|
| 104 | + $data = $this->filterErrorData( $data, $itemInfo, $errorInfo ); |
|
| 105 | 105 | |
| 106 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
| 106 | + $this->addMessage( $phpcsFile, $error, $stackPtr, $errorInfo[ 'error' ], $errorCode, $data ); |
|
| 107 | 107 | } |
| 108 | 108 | } |
@@ -18,8 +18,7 @@ discard block |
||
| 18 | 18 | * @package PHPCompatibility |
| 19 | 19 | * @author Juliette Reinders Folmer <[email protected]> |
| 20 | 20 | */ |
| 21 | -abstract class AbstractNewFeatureSniff extends AbstractComplexVersionSniff |
|
| 22 | -{ |
|
| 21 | +abstract class AbstractNewFeatureSniff extends AbstractComplexVersionSniff { |
|
| 23 | 22 | |
| 24 | 23 | |
| 25 | 24 | /** |
@@ -29,8 +28,7 @@ discard block |
||
| 29 | 28 | * |
| 30 | 29 | * @return bool |
| 31 | 30 | */ |
| 32 | - protected function shouldThrowError(array $errorInfo) |
|
| 33 | - { |
|
| 31 | + protected function shouldThrowError(array $errorInfo) { |
|
| 34 | 32 | return ($errorInfo['not_in_version'] !== ''); |
| 35 | 33 | } |
| 36 | 34 | |
@@ -43,8 +41,7 @@ discard block |
||
| 43 | 41 | * |
| 44 | 42 | * @return array |
| 45 | 43 | */ |
| 46 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
| 47 | - { |
|
| 44 | + public function getErrorInfo(array $itemArray, array $itemInfo) { |
|
| 48 | 45 | $errorInfo = array( |
| 49 | 46 | 'not_in_version' => '', |
| 50 | 47 | 'error' => true, |
@@ -71,8 +68,7 @@ discard block |
||
| 71 | 68 | * |
| 72 | 69 | * @return string |
| 73 | 70 | */ |
| 74 | - protected function getErrorMsgTemplate() |
|
| 75 | - { |
|
| 71 | + protected function getErrorMsgTemplate() { |
|
| 76 | 72 | return '%s is not present in PHP version %s or earlier'; |
| 77 | 73 | } |
| 78 | 74 | |
@@ -89,8 +85,7 @@ discard block |
||
| 89 | 85 | * |
| 90 | 86 | * @return void |
| 91 | 87 | */ |
| 92 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
| 93 | - { |
|
| 88 | + public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) { |
|
| 94 | 89 | $itemName = $this->getItemName($itemInfo, $errorInfo); |
| 95 | 90 | $error = $this->getErrorMsgTemplate(); |
| 96 | 91 | |
@@ -26,52 +26,52 @@ |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Handle the retrieval of relevant information and - if necessary - throwing of an |
|
| 31 | - * error/warning for an item. |
|
| 32 | - * |
|
| 33 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 34 | - * @param int $stackPtr The position of the relevant token in |
|
| 35 | - * the stack. |
|
| 36 | - * @param array $itemInfo Base information about the item. |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo); |
|
| 29 | + /** |
|
| 30 | + * Handle the retrieval of relevant information and - if necessary - throwing of an |
|
| 31 | + * error/warning for an item. |
|
| 32 | + * |
|
| 33 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 34 | + * @param int $stackPtr The position of the relevant token in |
|
| 35 | + * the stack. |
|
| 36 | + * @param array $itemInfo Base information about the item. |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo); |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
| 45 | - * |
|
| 46 | - * @param array $itemInfo Base information about the item. |
|
| 47 | - * |
|
| 48 | - * @return array Version and other information about the item. |
|
| 49 | - */ |
|
| 50 | - public function getItemArray(array $itemInfo); |
|
| 43 | + /** |
|
| 44 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
| 45 | + * |
|
| 46 | + * @param array $itemInfo Base information about the item. |
|
| 47 | + * |
|
| 48 | + * @return array Version and other information about the item. |
|
| 49 | + */ |
|
| 50 | + public function getItemArray(array $itemInfo); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
| 55 | - * |
|
| 56 | - * @param array $itemArray Version and other information about the item. |
|
| 57 | - * @param array $itemInfo Base information about the item. |
|
| 58 | - * |
|
| 59 | - * @return array |
|
| 60 | - */ |
|
| 61 | - public function getErrorInfo(array $itemArray, array $itemInfo); |
|
| 53 | + /** |
|
| 54 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
| 55 | + * |
|
| 56 | + * @param array $itemArray Version and other information about the item. |
|
| 57 | + * @param array $itemInfo Base information about the item. |
|
| 58 | + * |
|
| 59 | + * @return array |
|
| 60 | + */ |
|
| 61 | + public function getErrorInfo(array $itemArray, array $itemInfo); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Generates the error or warning for this item. |
|
| 66 | - * |
|
| 67 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 68 | - * @param int $stackPtr The position of the relevant token in |
|
| 69 | - * the stack. |
|
| 70 | - * @param array $itemInfo Base information about the item. |
|
| 71 | - * @param array $errorInfo Array with detail (version) information |
|
| 72 | - * relevant to the item. |
|
| 73 | - * |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo); |
|
| 64 | + /** |
|
| 65 | + * Generates the error or warning for this item. |
|
| 66 | + * |
|
| 67 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
| 68 | + * @param int $stackPtr The position of the relevant token in |
|
| 69 | + * the stack. |
|
| 70 | + * @param array $itemInfo Base information about the item. |
|
| 71 | + * @param array $errorInfo Array with detail (version) information |
|
| 72 | + * relevant to the item. |
|
| 73 | + * |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo); |
|
| 77 | 77 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return void |
| 39 | 39 | */ |
| 40 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo); |
|
| 40 | + public function handleFeature( File $phpcsFile, $stackPtr, array $itemInfo ); |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return array Version and other information about the item. |
| 49 | 49 | */ |
| 50 | - public function getItemArray(array $itemInfo); |
|
| 50 | + public function getItemArray( array $itemInfo ); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return array |
| 60 | 60 | */ |
| 61 | - public function getErrorInfo(array $itemArray, array $itemInfo); |
|
| 61 | + public function getErrorInfo( array $itemArray, array $itemInfo ); |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -73,5 +73,5 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return void |
| 75 | 75 | */ |
| 76 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo); |
|
| 76 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ); |
|
| 77 | 77 | } |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | * @package PHPCompatibility |
| 23 | 23 | * @author Juliette Reinders Folmer <[email protected]> |
| 24 | 24 | */ |
| 25 | -interface ComplexVersionInterface |
|
| 26 | -{ |
|
| 25 | +interface ComplexVersionInterface { |
|
| 27 | 26 | |
| 28 | 27 | |
| 29 | 28 | /** |