| Conditions | 11 |
| Paths | 21 |
| Total Lines | 34 |
| Lines | 8 |
| Ratio | 23.53 % |
| 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 |
||
| 21 | public static $command; |
||
| 22 | |||
| 23 | |||
| 24 | public static function check($tokens, $absFilePath, $classFilePath, $psr4Path, $psr4Namespace) |
||
| 25 | { |
||
| 26 | $fullNamespace = RoutelessActions::getFullNamespace($classFilePath, $psr4Path, $psr4Namespace); |
||
| 27 | |||
| 28 | if (RoutelessActions::isLaravelController($fullNamespace)) { |
||
| 29 | self::removeGenericDocBlocks($tokens, $classFilePath->getRealpath()); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | private static function isValidDockBlock($tokenType, $tokenContent) |
||
| 34 | { |
||
| 35 | return $tokenType == T_DOC_COMMENT && Str::contains($tokenContent, self::LARAVEL_DOCBLOCK_CONTENT); |
||
| 36 | } |
||
| 37 | |||
| 38 | private static function removeGenericDocBlocks($tokens, $absFilePath) |
||
| 39 | { |
||
| 40 | foreach ($tokens as $i => $token) { |
||
| 41 | if (self::isValidDockBlock($token(0), $token(1))) { |
||
| 42 | unset($tokens[$i]); |
||
| 43 | if ($tokens[$i + 1][0] == T_WHITESPACE) { |
||
| 44 | unset($tokens[$i + 1]); |
||
| 45 | } |
||
| 46 | Refactor::saveTokens($absFilePath, $tokens); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | if (\in_array($token[0], [T_PUBLIC, T_PRIVATE, T_PROTECTED]) && ($tokens[$i - 1][0] == T_WHITESPACE)) { |
||
| 51 | if (($tokens[$i - 2][0] == '}') && $tokens[$i - 1][1] != "\n\n ") { |
||
| 52 | $tokens[$i - 1][1] = "\n\n "; |
||
| 53 | Refactor::saveTokens($absFilePath, $tokens); |
||
| 54 | } |
||
| 55 | |||
| 64 |