| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| 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 declare(strict_types=1); |
||
| 66 | public function createTokenHandler(): array |
||
| 67 | { |
||
| 68 | return [ |
||
| 69 | self::TOKEN_INCLUDE => function (string $currentLine, int $lineNumber, Script $script): string { |
||
| 70 | $path = $this->findInclude($script, $this->removeFromStart(self::TOKEN_INCLUDE, $currentLine)); |
||
| 71 | $includeScript = new Script(pathinfo($path, PATHINFO_DIRNAME), pathinfo($path, PATHINFO_BASENAME)); |
||
| 72 | |||
| 73 | $commands = $this->loadScript($includeScript); |
||
| 74 | $this->commandBuilder->replaceCommands($commands); |
||
| 75 | |||
| 76 | return ''; |
||
| 77 | }, |
||
| 78 | |||
| 79 | self::TOKEN_TEMPLATE => function (string $currentLine, int $lineNumber, Script $script): string { |
||
| 80 | $definition = $this->removeFromStart(self::TOKEN_TEMPLATE, $currentLine); |
||
| 81 | list($rawSource, $rawDestination) = explode(':', $definition); |
||
| 82 | |||
| 83 | $source = $script->getDirectory() . '/' . $rawSource; |
||
| 84 | $destination = $script->getDirectory() . '/' . $rawDestination; |
||
| 85 | |||
| 86 | $this->commandBuilder |
||
| 87 | ->addTemplateCommand($source, $destination, $lineNumber); |
||
| 88 | |||
| 89 | return ''; |
||
| 90 | }, |
||
| 91 | |||
| 92 | self::TOKEN_WAIT => function (string $currentLine, int $lineNumber): string { |
||
| 93 | $this->commandBuilder |
||
| 94 | ->addWaitCommand($lineNumber); |
||
| 95 | |||
| 96 | |||
| 97 | return ''; |
||
| 98 | }, |
||
| 99 | |||
| 100 | self::TOKEN_MODIFIER_IGNORE_ERROR => function (string $currentLine): string { |
||
| 101 | $this->commandBuilder->setIgnoreError(); |
||
| 102 | |||
| 103 | return $this->removeFromStart(self::TOKEN_MODIFIER_IGNORE_ERROR, $currentLine); |
||
| 104 | }, |
||
| 105 | |||
| 106 | self::TOKEN_MODIFIER_TTY => function (string $currentLine): string { |
||
| 107 | $this->commandBuilder->setTty(); |
||
| 108 | |||
| 109 | return $this->removeFromStart(self::TOKEN_MODIFIER_TTY, $currentLine); |
||
| 110 | }, |
||
| 111 | |||
| 112 | self::TOKEN_MODIFIER_DEFERRED => function (string $currentLine): string { |
||
| 113 | $this->commandBuilder->setDeferredExecution(); |
||
| 114 | |||
| 115 | return $this->removeFromStart(self::TOKEN_MODIFIER_DEFERRED, $currentLine); |
||
| 116 | }, |
||
| 117 | |||
| 118 | self::TOKEN_WILDCARD => function (string $currentLine, int $lineNumber): string { |
||
| 119 | $this->commandBuilder |
||
| 120 | ->addProcessCommand($currentLine, $lineNumber); |
||
| 121 | |||
| 122 | return ''; |
||
| 123 | }, |
||
| 124 | ]; |
||
| 125 | } |
||
| 126 | |||
| 222 |