| Conditions | 14 |
| Paths | 67 |
| Total Lines | 73 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 49 | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 50 | { |
||
| 51 | if ($this->supportsAbove('7.0') === false) { |
||
| 52 | return; |
||
| 53 | } |
||
| 54 | |||
| 55 | $tokens = $phpcsFile->getTokens(); |
||
| 56 | $endOfStatement = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), ($stackPtr + 1)); |
||
| 57 | if ($endOfStatement === false) { |
||
| 58 | // No semi-colon - live coding. |
||
| 59 | return; |
||
| 60 | } |
||
| 61 | |||
| 62 | for ($ptr = ($stackPtr + 1); $ptr <= $endOfStatement; $ptr++) { |
||
| 63 | $errorThrown = false; |
||
| 64 | $nextComma = $phpcsFile->findNext(T_COMMA, $ptr, $endOfStatement, false, null, true); |
||
| 65 | $varEnd = ($nextComma === false) ? $endOfStatement : $nextComma; |
||
| 66 | $variable = $phpcsFile->findNext(T_VARIABLE, $ptr, $varEnd); |
||
| 67 | $varString = trim($phpcsFile->getTokensAsString($ptr, ($varEnd - $ptr))); |
||
| 68 | $data = array($varString); |
||
| 69 | |||
| 70 | if ($variable !== false) { |
||
| 71 | |||
| 72 | $prev = $phpcsFile->findPrevious(\PHP_CodeSniffer_Tokens::$emptyTokens, ($variable - 1), $ptr, true); |
||
| 73 | |||
| 74 | if ($prev !== false && $tokens[$prev]['type'] === 'T_DOLLAR') { |
||
| 75 | |||
| 76 | $next = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($variable + 1), $varEnd, true); |
||
| 77 | |||
| 78 | if ($next !== false |
||
| 79 | && in_array($tokens[$next]['code'], array(T_OPEN_SQUARE_BRACKET, T_OBJECT_OPERATOR, T_DOUBLE_COLON), true) === true |
||
| 80 | ) { |
||
| 81 | $phpcsFile->addError( |
||
| 82 | 'Global with variable variables is not allowed since PHP 7.0. Found %s', |
||
| 83 | $variable, |
||
| 84 | 'Found', |
||
| 85 | $data |
||
| 86 | ); |
||
| 87 | $errorThrown = true; |
||
| 88 | } else { |
||
| 89 | $phpcsFile->addWarning( |
||
| 90 | 'Global with anything other than bare variables is discouraged since PHP 7.0. Found %s', |
||
| 91 | $variable, |
||
| 92 | 'NonBareVariableFound', |
||
| 93 | $data |
||
| 94 | ); |
||
| 95 | $errorThrown = true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | if ($errorThrown === false) { |
||
| 101 | $dollar = $phpcsFile->findNext(T_DOLLAR, $ptr, $varEnd); |
||
| 102 | if ($dollar !== false) { |
||
| 103 | $next = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($dollar + 1), $varEnd, true); |
||
| 104 | if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) { |
||
| 105 | $phpcsFile->addWarning( |
||
| 106 | 'Global with anything other than bare variables is discouraged since PHP 7.0. Found %s', |
||
| 107 | $dollar, |
||
| 108 | 'NonBareVariableFound', |
||
| 109 | $data |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // Move the stack pointer forward to the next variable for multi-variable statements. |
||
| 116 | if ($nextComma === false) { |
||
| 117 | break; |
||
| 118 | } |
||
| 119 | $ptr = $nextComma; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 |