| Conditions | 11 |
| Paths | 15 |
| Total Lines | 55 |
| Code Lines | 34 |
| Lines | 18 |
| Ratio | 32.73 % |
| 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 |
||
| 48 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 49 | { |
||
| 50 | if ($this->supportsBelow('5.4') === false) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | $tokens = $phpcsFile->getTokens(); |
||
| 55 | |||
| 56 | switch($tokens[$stackPtr]['code']) { |
||
| 57 | case T_CONSTANT_ENCAPSED_STRING: |
||
| 58 | $type = 'string literals'; |
||
| 59 | $end = $stackPtr; |
||
| 60 | break; |
||
| 61 | |||
| 62 | View Code Duplication | case T_ARRAY: |
|
|
1 ignored issue
–
show
|
|||
| 63 | if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) { |
||
| 64 | // Live coding. |
||
| 65 | return; |
||
| 66 | } else { |
||
| 67 | $type = 'arrays'; |
||
| 68 | $end = $tokens[$stackPtr]['parenthesis_closer']; |
||
| 69 | } |
||
| 70 | break; |
||
| 71 | |||
| 72 | View Code Duplication | case T_OPEN_SHORT_ARRAY: |
|
|
1 ignored issue
–
show
|
|||
| 73 | if (isset($tokens[$stackPtr]['bracket_closer']) === false) { |
||
| 74 | // Live coding. |
||
| 75 | return; |
||
| 76 | } else { |
||
| 77 | $type = 'arrays'; |
||
| 78 | $end = $tokens[$stackPtr]['bracket_closer']; |
||
| 79 | } |
||
| 80 | break; |
||
| 81 | } |
||
| 82 | |||
| 83 | if (isset($type, $end) === false) { |
||
| 84 | // Shouldn't happen, but for some reason did. |
||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | $nextNonEmpty = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), null, true, null, true); |
||
| 89 | |||
| 90 | if ($nextNonEmpty !== false && |
||
| 91 | ($tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET' || |
||
| 92 | $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SHORT_ARRAY') // Work around bug #1381 in PHPCS 2.8.1 and lower. |
||
| 93 | ) { |
||
| 94 | $phpcsFile->addError( |
||
| 95 | 'Direct array dereferencing of %s is not present in PHP version 5.4 or earlier', |
||
| 96 | $nextNonEmpty, |
||
| 97 | 'Found', |
||
| 98 | array($type) |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | |||
| 102 | }//end process() |
||
| 103 | |||
| 105 |
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.