| Conditions | 8 |
| Paths | 18 |
| Total Lines | 52 |
| 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 checkSpacing(File $phpcsFile, $stackPtr, $before) |
||
| 75 | { |
||
| 76 | if ($before === true) { |
||
| 77 | $stackPtrDiff = -1; |
||
| 78 | $errorWord = 'prefix'; |
||
| 79 | $errorCode = 'Before'; |
||
| 80 | } else { |
||
| 81 | $stackPtrDiff = 1; |
||
| 82 | $errorWord = 'follow'; |
||
| 83 | $errorCode = 'After'; |
||
| 84 | } |
||
| 85 | |||
| 86 | $tokens = $phpcsFile->getTokens(); |
||
| 87 | $tokenData = $tokens[($stackPtr + $stackPtrDiff)]; |
||
| 88 | |||
| 89 | if ($tokenData['code'] !== T_WHITESPACE) { |
||
| 90 | $error = 'Whitespace must '.$errorWord.' the item assignment operator =>'; |
||
| 91 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpacing'.$errorCode); |
||
| 92 | if ($fix === true) { |
||
| 93 | $phpcsFile->fixer->beginChangeset(); |
||
| 94 | |||
| 95 | if ($before === true) { |
||
| 96 | $phpcsFile->fixer->addContentBefore($stackPtr, ' '); |
||
| 97 | } else { |
||
| 98 | $phpcsFile->fixer->addContent($stackPtr, ' '); |
||
| 99 | } |
||
| 100 | |||
| 101 | $phpcsFile->fixer->endChangeset(); |
||
| 102 | } |
||
| 103 | |||
| 104 | return; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (isset($tokenData['orig_content']) === true) { |
||
| 108 | $content = $tokenData['orig_content']; |
||
| 109 | } else { |
||
| 110 | $content = $tokenData['content']; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($this->hasOnlySpaces($content) === false) { |
||
| 114 | $error = 'Spaces must be used to '.$errorWord.' the item assignment operator =>'; |
||
| 115 | $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MixedWhitespace'.$errorCode); |
||
| 116 | if ($fix === true) { |
||
| 117 | $phpcsFile->fixer->beginChangeset(); |
||
| 118 | $phpcsFile->fixer->replaceToken( |
||
| 119 | ($stackPtr + $stackPtrDiff), |
||
| 120 | str_repeat(' ', strlen($content)) |
||
| 121 | ); |
||
| 122 | $phpcsFile->fixer->endChangeset(); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | }//end checkSpacing() |
||
| 126 | |||
| 140 |