| Conditions | 9 |
| Paths | 11 |
| Total Lines | 64 |
| Code Lines | 40 |
| Lines | 5 |
| Ratio | 7.81 % |
| 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 |
||
| 55 | public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 56 | { |
||
| 57 | if ($this->supportsBelow('7.2') === false) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | $tokens = $phpcsFile->getTokens(); |
||
| 62 | |||
| 63 | $nextNonEmpty = $phpcsFile->findNext(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
||
| 64 | View Code Duplication | if ($tokens[$nextNonEmpty]['code'] !== T_OPEN_PARENTHESIS |
|
| 65 | || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
||
| 66 | ) { |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($tokens[$stackPtr]['code'] === T_STRING) { |
||
| 71 | $ignore = array( |
||
| 72 | T_FUNCTION => true, |
||
| 73 | T_CONST => true, |
||
| 74 | T_USE => true, |
||
| 75 | ); |
||
| 76 | |||
| 77 | $prevNonEmpty = $phpcsFile->findPrevious(\PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
||
| 78 | if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) { |
||
| 79 | // Not a function call. |
||
| 80 | return; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
||
| 85 | $lastInParenthesis = $phpcsFile->findPrevious( |
||
| 86 | \PHP_CodeSniffer_Tokens::$emptyTokens, |
||
| 87 | ($closer - 1), |
||
| 88 | $nextNonEmpty, |
||
| 89 | true |
||
| 90 | ); |
||
| 91 | |||
| 92 | if ($tokens[$lastInParenthesis]['code'] !== T_COMMA) { |
||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | $data = array(); |
||
| 97 | switch ($tokens[$stackPtr]['code']) { |
||
| 98 | case T_ISSET: |
||
| 99 | $data[] = 'calls to isset()'; |
||
| 100 | break; |
||
| 101 | |||
| 102 | case T_UNSET: |
||
| 103 | $data[] = 'calls to unset()'; |
||
| 104 | break; |
||
| 105 | |||
| 106 | default: |
||
| 107 | $data[] = 'function calls'; |
||
| 108 | break; |
||
| 109 | } |
||
| 110 | |||
| 111 | $phpcsFile->addError( |
||
| 112 | 'Trailing comma\'s are not allowed in %s in PHP 7.2 or earlier', |
||
| 113 | $lastInParenthesis, |
||
| 114 | 'Found', |
||
| 115 | $data |
||
| 116 | ); |
||
| 117 | |||
| 118 | }//end process() |
||
| 119 | |||
| 121 |