| Conditions | 10 |
| Paths | 8 |
| Total Lines | 44 |
| Code Lines | 24 |
| 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 |
||
| 38 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 39 | { |
||
| 40 | if ($this->supportsBelow('5.3') === false) { |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | $tokens = $phpcsFile->getTokens(); |
||
| 45 | |||
| 46 | // Next non-empty token should be the open parenthesis. |
||
| 47 | $openParenthesis = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
||
| 48 | if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== T_OPEN_PARENTHESIS) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | // Don't throw errors during live coding. |
||
| 53 | if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | // Is this T_STRING really a function or method call ? |
||
| 58 | $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
||
| 59 | if($prevToken !== false && in_array($tokens[$prevToken]['code'], array(T_DOUBLE_COLON, T_OBJECT_OPERATOR), true) === false) { |
||
| 60 | $ignore = array( |
||
| 61 | T_FUNCTION, |
||
| 62 | T_CONST, |
||
| 63 | T_USE, |
||
| 64 | T_NEW, |
||
| 65 | T_CLASS, |
||
| 66 | T_INTERFACE, |
||
| 67 | ); |
||
| 68 | |||
| 69 | if (in_array($tokens[$prevToken]['code'], $ignore) === true) { |
||
| 70 | // Not a call to a PHP function or method. |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer']; |
||
| 76 | $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true); |
||
| 77 | if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') { |
||
| 78 | $phpcsFile->addError('Function array dereferencing is not present in PHP version 5.3 or earlier', $nextNonEmpty); |
||
| 79 | } |
||
| 80 | |||
| 81 | }//end process() |
||
| 82 | }//end class |
||
| 83 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.