| Conditions | 7 |
| Paths | 20 |
| Total Lines | 54 |
| Code Lines | 35 |
| Lines | 32 |
| Ratio | 59.26 % |
| 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 |
||
| 65 | public function process(File $phpcsFile, $stackPtr) |
||
| 66 | { |
||
| 67 | $tokens = $phpcsFile->getTokens(); |
||
| 68 | $current = $tokens[$stackPtr]; |
||
| 69 | |||
| 70 | if ($current['code'] === T_ARRAY) { |
||
| 71 | $arrayType = 'parenthesis'; |
||
| 72 | $start = $current['parenthesis_opener']; |
||
| 73 | $end = $current['parenthesis_closer']; |
||
| 74 | } else { |
||
| 75 | $arrayType = 'bracket'; |
||
| 76 | $start = $current['bracket_opener']; |
||
| 77 | $end = $current['bracket_closer']; |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($tokens[$start]['line'] === $tokens[$end]['line']) { |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | View Code Duplication | if ($tokens[($start + 2)]['line'] === $tokens[$start]['line']) { |
|
| 85 | $fixable = $phpcsFile->addFixableError( |
||
| 86 | sprintf( |
||
| 87 | 'opening %s of multi line array must be followed by newline', |
||
| 88 | $arrayType |
||
| 89 | ), |
||
| 90 | $start, |
||
| 91 | 'OpeningMustBeFollowedByNewline' |
||
| 92 | ); |
||
| 93 | |||
| 94 | if ($fixable === true) { |
||
| 95 | $phpcsFile->fixer->beginChangeset(); |
||
| 96 | $phpcsFile->fixer->addNewline($start); |
||
| 97 | $phpcsFile->fixer->endChangeset(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | View Code Duplication | if ($tokens[($end - 2)]['line'] === $tokens[$end]['line']) { |
|
| 102 | $fixable = $phpcsFile->addFixableError( |
||
| 103 | sprintf( |
||
| 104 | 'closing %s of multi line array must in own line', |
||
| 105 | $arrayType |
||
| 106 | ), |
||
| 107 | $end, |
||
| 108 | 'ClosingMustBeInOwnLine' |
||
| 109 | ); |
||
| 110 | |||
| 111 | if ($fixable === true) { |
||
| 112 | $phpcsFile->fixer->beginChangeset(); |
||
| 113 | $phpcsFile->fixer->addNewlineBefore($end); |
||
| 114 | $phpcsFile->fixer->endChangeset(); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | }//end process() |
||
| 119 | |||
| 122 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.