| Conditions | 8 |
| Paths | 14 |
| Total Lines | 62 |
| 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 |
||
| 74 | protected function checkContent(File $phpcsFile, $stackPtr, $before) |
||
| 75 | { |
||
| 76 | if ($before === true) { |
||
| 77 | $contentToken = ($phpcsFile->findPrevious( |
||
| 78 | T_WHITESPACE, |
||
| 79 | ($stackPtr - 1), |
||
| 80 | null, |
||
| 81 | true |
||
| 82 | ) + 1); |
||
| 83 | $errorWord = 'before'; |
||
| 84 | } else { |
||
| 85 | $contentToken = ($phpcsFile->findNext( |
||
| 86 | T_WHITESPACE, |
||
| 87 | ($stackPtr + 1), |
||
| 88 | null, |
||
| 89 | true |
||
| 90 | ) - 1); |
||
| 91 | $errorWord = 'after'; |
||
| 92 | } |
||
| 93 | |||
| 94 | $tokens = $phpcsFile->getTokens(); |
||
| 95 | $contentData = $tokens[$contentToken]; |
||
| 96 | |||
| 97 | if ($contentData['line'] !== $tokens[$stackPtr]['line']) { |
||
| 98 | // Ignore concat operator split across several lines. |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($contentData['code'] !== T_WHITESPACE) { |
||
| 103 | $fix = $phpcsFile->addFixableError( |
||
| 104 | 'Expected 1 space '.$errorWord.' concat operator; 0 found', |
||
| 105 | $stackPtr, |
||
| 106 | 'NoSpace'.ucfirst($errorWord) |
||
| 107 | ); |
||
| 108 | |||
| 109 | if ($fix === true) { |
||
| 110 | $phpcsFile->fixer->beginChangeset(); |
||
| 111 | |||
| 112 | if ($before === true) { |
||
| 113 | $phpcsFile->fixer->addContentBefore($stackPtr, ' '); |
||
| 114 | } else { |
||
| 115 | $phpcsFile->fixer->addContent($stackPtr, ' '); |
||
| 116 | } |
||
| 117 | |||
| 118 | $phpcsFile->fixer->endChangeset(); |
||
| 119 | } |
||
| 120 | } elseif ($contentData['length'] !== 1) { |
||
| 121 | $data = array($contentData['length']); |
||
| 122 | $fix = $phpcsFile->addFixableError( |
||
| 123 | 'Expected 1 space '.$errorWord.' concat operator; %s found', |
||
| 124 | $stackPtr, |
||
| 125 | 'SpaceBefore'.ucfirst($errorWord), |
||
| 126 | $data |
||
| 127 | ); |
||
| 128 | |||
| 129 | if ($fix === true) { |
||
| 130 | $phpcsFile->fixer->beginChangeset(); |
||
| 131 | $phpcsFile->fixer->replaceToken($contentToken, ' '); |
||
| 132 | $phpcsFile->fixer->endChangeset(); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | }//end checkContent() |
||
| 136 | }//end class |
||
| 137 |