Conditions | 11 |
Paths | 9 |
Total Lines | 41 |
Code Lines | 20 |
Lines | 6 |
Ratio | 14.63 % |
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 |
||
56 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
57 | { |
||
58 | if ($this->supportsBelow('5.2') === false) { |
||
59 | return; |
||
60 | } |
||
61 | |||
62 | $tokens = $phpcsFile->getTokens(); |
||
63 | $tokenType = $tokens[$stackPtr]['type']; |
||
64 | $isOldPhp = (PHP_VERSION_ID < 50300); |
||
65 | |||
66 | /* |
||
67 | * In PHP 5.2 the T_NOWDOC tokens aren't recognized yet and PHPCS does not |
||
68 | * backfill for it, so we have to sniff for a specific combination of tokens. |
||
69 | */ |
||
70 | if ($isOldPhp === true && $tokenType === 'T_SL' ) { |
||
71 | View Code Duplication | if (isset($tokens[($stackPtr+1)]) === false || $tokens[($stackPtr+1)]['type'] !== 'T_LESS_THAN') { |
|
1 ignored issue
–
show
|
|||
72 | return; |
||
73 | } |
||
74 | |||
75 | View Code Duplication | if (isset($tokens[($stackPtr+2)]) === false || $tokens[($stackPtr+2)]['type'] !== 'T_CONSTANT_ENCAPSED_STRING') { |
|
1 ignored issue
–
show
|
|||
76 | return; |
||
77 | } |
||
78 | |||
79 | if (preg_match('`^\'([a-z][a-z0-9_]*)\'$`iD', $tokens[($stackPtr+2)]['content'], $matches ) < 1) { |
||
80 | return; |
||
81 | } |
||
82 | |||
83 | $closer = $phpcsFile->findNext(T_STRING, ($stackPtr + 3), null, false, $matches[1], true); |
||
84 | if ($closer === false) { |
||
85 | return; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | $phpcsFile->addError( 'Nowdocs are not present in PHP version 5.2 or earlier.', $stackPtr, 'Found' ); |
||
90 | |||
91 | if (isset($closer) !== false) { |
||
92 | $phpcsFile->addError( 'Nowdocs are not present in PHP version 5.2 or earlier.', $closer, 'Found' ); |
||
1 ignored issue
–
show
|
|||
93 | return ($closer + 1); |
||
94 | } |
||
95 | |||
96 | }//end process() |
||
97 | |||
99 |
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.