| Conditions | 10 |
| Paths | 27 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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 |
||
| 51 | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 52 | { |
||
| 53 | if ($this->supportsBelow('7.1') === false) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | $tokens = $phpcsFile->getTokens(); |
||
| 58 | $token = $tokens[$stackPtr]; |
||
| 59 | |||
| 60 | // Deal with PHPCS pre-2.6.0. |
||
| 61 | if ($token['code'] === T_USE) { |
||
| 62 | $hasCurlyBrace = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
||
| 63 | if ($hasCurlyBrace === false) { |
||
| 64 | return; |
||
| 65 | } |
||
| 66 | |||
| 67 | $prevToken = $phpcsFile->findPrevious(\PHP_CodeSniffer_Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
||
| 68 | if ($prevToken === false || $tokens[$prevToken]['code'] !== T_NS_SEPARATOR) { |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | $stackPtr = $hasCurlyBrace; |
||
| 73 | } |
||
| 74 | |||
| 75 | // Still here ? In that case, it is a group use statement. |
||
| 76 | if ($this->supportsBelow('5.6') === true) { |
||
| 77 | $phpcsFile->addError( |
||
| 78 | 'Group use declarations are not allowed in PHP 5.6 or earlier', |
||
| 79 | $stackPtr, |
||
| 80 | 'Found' |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | $closers = array(T_CLOSE_CURLY_BRACKET); |
||
| 85 | if (defined('T_CLOSE_USE_GROUP')) { |
||
| 86 | $closers[] = T_CLOSE_USE_GROUP; |
||
| 87 | } |
||
| 88 | |||
| 89 | $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true); |
||
| 90 | if ($closeCurly === false) { |
||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | $prevToken = $phpcsFile->findPrevious(\PHP_CodeSniffer_Tokens::$emptyTokens, ($closeCurly - 1), null, true); |
||
| 95 | if ($tokens[$prevToken]['code'] === T_COMMA) { |
||
| 96 | $phpcsFile->addError( |
||
| 97 | 'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier', |
||
| 98 | $prevToken, |
||
| 99 | 'TrailingCommaFound' |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | }//end process() |
||
| 103 | |||
| 105 |