| Conditions | 9 |
| Paths | 16 |
| Total Lines | 53 |
| 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 |
||
| 61 | public function process(File $phpcsFile, $stackPtr) |
||
| 62 | { |
||
| 63 | $tokens = $phpcsFile->getTokens(); |
||
| 64 | $declarationEndPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); |
||
| 65 | |||
| 66 | $nextCodePtr = $phpcsFile->findNext( |
||
| 67 | T_WHITESPACE, |
||
| 68 | ($declarationEndPtr + 1), |
||
| 69 | null, |
||
| 70 | true |
||
| 71 | ); |
||
| 72 | |||
| 73 | if ($nextCodePtr === false) { |
||
| 74 | return; |
||
| 75 | } |
||
| 76 | |||
| 77 | $diff = ($tokens[$nextCodePtr]['line'] - $tokens[$declarationEndPtr]['line'] - 1); |
||
| 78 | |||
| 79 | if ($diff === $this->emptyLineCount) { |
||
| 80 | return; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($diff < 0) { |
||
| 84 | $diff = 0; |
||
| 85 | } |
||
| 86 | |||
| 87 | $data = array($diff); |
||
| 88 | $error = 'Expected '.$this->emptyLineCount.' blank line(-s) after namespace declaration; %s found'; |
||
| 89 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BlankLineAfter', $data); |
||
| 90 | |||
| 91 | if ($fix === false) { |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | $phpcsFile->fixer->beginChangeset(); |
||
| 96 | |||
| 97 | if ($diff > 0) { |
||
| 98 | for ($j = ($declarationEndPtr + 1); $j < $nextCodePtr; $j++) { |
||
| 99 | if ($tokens[$j]['line'] === $tokens[$nextCodePtr]['line']) { |
||
| 100 | // Keep existing indentation. |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | $phpcsFile->fixer->replaceToken($j, ''); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | for ($i = 0; $i <= $this->emptyLineCount; $i++) { |
||
| 109 | $phpcsFile->fixer->addNewline($declarationEndPtr); |
||
| 110 | } |
||
| 111 | |||
| 112 | $phpcsFile->fixer->endChangeset(); |
||
| 113 | }//end process() |
||
| 114 | }//end class |
||
| 115 |