@@ -158,15 +158,15 @@ |
||
| 158 | 158 | |
| 159 | 159 | $flows_data = self::get_flows_data(); |
| 160 | 160 | |
| 161 | - if ( ! isset( $flows_data[ $key ] ) ) { |
|
| 162 | - $flows_data[ $key ] = array(); |
|
| 161 | + if ( ! isset( $flows_data[$key] ) ) { |
|
| 162 | + $flows_data[$key] = array(); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ( ! isset( $flows_data[ $key ][ $value ] ) ) { |
|
| 166 | - $flows_data[ $key ][ $value ] = 0; |
|
| 165 | + if ( ! isset( $flows_data[$key][$value] ) ) { |
|
| 166 | + $flows_data[$key][$value] = 0; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $flows_data[ $key ][ $value ]++; |
|
| 169 | + $flows_data[$key][$value] ++; |
|
| 170 | 170 | update_option( self::FLOWS_ACTION_NAME, $flows_data ); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | $tokens = $phpcsFile->getTokens(); |
| 61 | 61 | |
| 62 | 62 | // Make sure this function has a scope. |
| 63 | - if ( ! isset( $tokens[ $stackPtr ]['scope_opener'] ) || ! isset( $tokens[ $stackPtr ]['scope_closer'] ) ) { |
|
| 63 | + if ( ! isset( $tokens[$stackPtr]['scope_opener'] ) || ! isset( $tokens[$stackPtr]['scope_closer'] ) ) { |
|
| 64 | 64 | return; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $functionOpener = $tokens[ $stackPtr ]['scope_opener']; |
|
| 68 | - $functionCloser = $tokens[ $stackPtr ]['scope_closer']; |
|
| 67 | + $functionOpener = $tokens[$stackPtr]['scope_opener']; |
|
| 68 | + $functionCloser = $tokens[$stackPtr]['scope_closer']; |
|
| 69 | 69 | |
| 70 | 70 | // Find the first statement in the function. |
| 71 | 71 | $firstStatement = $phpcsFile->findNext( T_WHITESPACE, $functionOpener + 1, $functionCloser, true ); |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Check if the first statement is a variable assignment. |
| 78 | - if ( $tokens[ $firstStatement ]['code'] !== T_VARIABLE ) { |
|
| 78 | + if ( $tokens[$firstStatement]['code'] !== T_VARIABLE ) { |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Get the variable name. |
| 83 | - $variableName = $tokens[ $firstStatement ]['content']; |
|
| 83 | + $variableName = $tokens[$firstStatement]['content']; |
|
| 84 | 84 | |
| 85 | 85 | // Check if this variable is a function parameter (skip those, especially by-reference params). |
| 86 | 86 | if ( $this->isVariableAParameter( $phpcsFile, $tokens, $stackPtr, $variableName ) ) { |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // Check if the next statement is an if with an early return. |
| 105 | - if ( $tokens[ $nextStatement ]['code'] !== T_IF ) { |
|
| 105 | + if ( $tokens[$nextStatement]['code'] !== T_IF ) { |
|
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Make sure the if has a scope. |
| 110 | - if ( ! isset( $tokens[ $nextStatement ]['scope_opener'] ) || ! isset( $tokens[ $nextStatement ]['scope_closer'] ) ) { |
|
| 110 | + if ( ! isset( $tokens[$nextStatement]['scope_opener'] ) || ! isset( $tokens[$nextStatement]['scope_closer'] ) ) { |
|
| 111 | 111 | return; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $ifOpener = $tokens[ $nextStatement ]['scope_opener']; |
|
| 115 | - $ifCloser = $tokens[ $nextStatement ]['scope_closer']; |
|
| 114 | + $ifOpener = $tokens[$nextStatement]['scope_opener']; |
|
| 115 | + $ifCloser = $tokens[$nextStatement]['scope_closer']; |
|
| 116 | 116 | |
| 117 | 117 | // Check if the if body contains only a return statement. |
| 118 | 118 | $ifFirstStatement = $phpcsFile->findNext( T_WHITESPACE, $ifOpener + 1, $ifCloser, true ); |
| 119 | 119 | |
| 120 | - if ( false === $ifFirstStatement || $tokens[ $ifFirstStatement ]['code'] !== T_RETURN ) { |
|
| 120 | + if ( false === $ifFirstStatement || $tokens[$ifFirstStatement]['code'] !== T_RETURN ) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | // Check if the if has an else/elseif - skip those. |
| 139 | 139 | $afterIfClose = $phpcsFile->findNext( T_WHITESPACE, $ifCloser + 1, $functionCloser, true ); |
| 140 | 140 | |
| 141 | - if ( false !== $afterIfClose && in_array( $tokens[ $afterIfClose ]['code'], array( T_ELSE, T_ELSEIF ), true ) ) { |
|
| 141 | + if ( false !== $afterIfClose && in_array( $tokens[$afterIfClose]['code'], array( T_ELSE, T_ELSEIF ), true ) ) { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -194,15 +194,15 @@ discard block |
||
| 194 | 194 | // Get the variable declaration content. |
| 195 | 195 | $varDeclaration = ''; |
| 196 | 196 | |
| 197 | - for ( $i = $varStart; $i <= $assignmentEnd; $i++ ) { |
|
| 198 | - $varDeclaration .= $tokens[ $i ]['content']; |
|
| 197 | + for ( $i = $varStart; $i <= $assignmentEnd; $i ++ ) { |
|
| 198 | + $varDeclaration .= $tokens[$i]['content']; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Find the start of the line for the variable (to get indentation). |
| 202 | 202 | $lineStart = $varStart; |
| 203 | 203 | |
| 204 | - for ( $i = $varStart - 1; $i >= 0; $i-- ) { |
|
| 205 | - if ( $tokens[ $i ]['line'] < $tokens[ $varStart ]['line'] ) { |
|
| 204 | + for ( $i = $varStart - 1; $i >= 0; $i -- ) { |
|
| 205 | + if ( $tokens[$i]['line'] < $tokens[$varStart]['line'] ) { |
|
| 206 | 206 | break; |
| 207 | 207 | } |
| 208 | 208 | $lineStart = $i; |
@@ -210,18 +210,18 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | // Get the indentation based on the variable's column position. |
| 212 | 212 | // Column is 1-indexed, so column 2 means 1 character of indentation. |
| 213 | - $column = $tokens[ $varStart ]['column']; |
|
| 213 | + $column = $tokens[$varStart]['column']; |
|
| 214 | 214 | $tabCount = (int) floor( ( $column - 1 ) / 4 ); |
| 215 | 215 | $indent = str_repeat( "\t", $tabCount ); |
| 216 | 216 | |
| 217 | 217 | // Remove the variable declaration line (from line start to semicolon). |
| 218 | - for ( $i = $lineStart; $i <= $assignmentEnd; $i++ ) { |
|
| 218 | + for ( $i = $lineStart; $i <= $assignmentEnd; $i ++ ) { |
|
| 219 | 219 | $phpcsFile->fixer->replaceToken( $i, '' ); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Also remove the newline after the semicolon if it exists. |
| 223 | - if ( isset( $tokens[ $assignmentEnd + 1 ] ) && $tokens[ $assignmentEnd + 1 ]['code'] === T_WHITESPACE ) { |
|
| 224 | - $wsContent = $tokens[ $assignmentEnd + 1 ]['content']; |
|
| 223 | + if ( isset( $tokens[$assignmentEnd + 1] ) && $tokens[$assignmentEnd + 1]['code'] === T_WHITESPACE ) { |
|
| 224 | + $wsContent = $tokens[$assignmentEnd + 1]['content']; |
|
| 225 | 225 | |
| 226 | 226 | // Remove one newline from the whitespace. |
| 227 | 227 | if ( strpos( $wsContent, "\n" ) === 0 ) { |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | // Find the whitespace after the if closer. |
| 234 | 234 | $afterIfCloser = $ifCloser + 1; |
| 235 | 235 | |
| 236 | - if ( isset( $tokens[ $afterIfCloser ] ) && $tokens[ $afterIfCloser ]['code'] === T_WHITESPACE ) { |
|
| 237 | - $existingWs = $tokens[ $afterIfCloser ]['content']; |
|
| 236 | + if ( isset( $tokens[$afterIfCloser] ) && $tokens[$afterIfCloser]['code'] === T_WHITESPACE ) { |
|
| 237 | + $existingWs = $tokens[$afterIfCloser]['content']; |
|
| 238 | 238 | // Add the variable declaration with proper formatting. |
| 239 | 239 | // Keep the existing whitespace structure but insert the variable declaration. |
| 240 | 240 | $newContent = "\n\n" . $indent . $varDeclaration . $existingWs; |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @return bool |
| 260 | 260 | */ |
| 261 | 261 | private function isVariableUsedInRange( File $phpcsFile, array $tokens, $start, $end, $variableName ) { |
| 262 | - for ( $i = $start; $i <= $end; $i++ ) { |
|
| 263 | - if ( $tokens[ $i ]['code'] === T_VARIABLE && $tokens[ $i ]['content'] === $variableName ) { |
|
| 262 | + for ( $i = $start; $i <= $end; $i ++ ) { |
|
| 263 | + if ( $tokens[$i]['code'] === T_VARIABLE && $tokens[$i]['content'] === $variableName ) { |
|
| 264 | 264 | return true; |
| 265 | 265 | } |
| 266 | 266 | } |
@@ -282,15 +282,15 @@ discard block |
||
| 282 | 282 | // Find the opening parenthesis of the function. |
| 283 | 283 | $openParen = $phpcsFile->findNext( T_OPEN_PARENTHESIS, $functionPtr + 1 ); |
| 284 | 284 | |
| 285 | - if ( false === $openParen || ! isset( $tokens[ $openParen ]['parenthesis_closer'] ) ) { |
|
| 285 | + if ( false === $openParen || ! isset( $tokens[$openParen]['parenthesis_closer'] ) ) { |
|
| 286 | 286 | return false; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $closeParen = $tokens[ $openParen ]['parenthesis_closer']; |
|
| 289 | + $closeParen = $tokens[$openParen]['parenthesis_closer']; |
|
| 290 | 290 | |
| 291 | 291 | // Look for the variable in the parameter list. |
| 292 | - for ( $i = $openParen + 1; $i < $closeParen; $i++ ) { |
|
| 293 | - if ( $tokens[ $i ]['code'] === T_VARIABLE && $tokens[ $i ]['content'] === $variableName ) { |
|
| 292 | + for ( $i = $openParen + 1; $i < $closeParen; $i ++ ) { |
|
| 293 | + if ( $tokens[$i]['code'] === T_VARIABLE && $tokens[$i]['content'] === $variableName ) { |
|
| 294 | 294 | return true; |
| 295 | 295 | } |
| 296 | 296 | } |