| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| 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); |
||
| 78 | private function createTokenHandler(ScriptLoader $loader): array |
||
| 79 | { |
||
| 80 | return [ |
||
| 81 | self::TOKEN_ACTION => function (string $currentLine) use ($loader): string { |
||
| 82 | $scriptName = $this->removeFromStart(self::TOKEN_ACTION, $currentLine); |
||
| 83 | $actionScript = $this->scriptFinder->findScriptByName($scriptName); |
||
| 84 | |||
| 85 | $commands = $loader->loadScript($actionScript); |
||
| 86 | $this->commandBuilder->replaceCommands($commands); |
||
| 87 | |||
| 88 | return ''; |
||
| 89 | }, |
||
| 90 | |||
| 91 | self::TOKEN_INCLUDE => function (string $currentLine, int $lineNumber, Script $script) use ($loader): string { |
||
| 92 | $path = $this->findInclude($script, $this->removeFromStart(self::TOKEN_INCLUDE, $currentLine)); |
||
| 93 | $includeScript = new Script(pathinfo($path, PATHINFO_DIRNAME), pathinfo($path, PATHINFO_BASENAME)); |
||
| 94 | |||
| 95 | $commands = $loader->loadScript($includeScript); |
||
| 96 | $this->commandBuilder->replaceCommands($commands); |
||
| 97 | |||
| 98 | return ''; |
||
| 99 | }, |
||
| 100 | |||
| 101 | self::TOKEN_TEMPLATE => function (string $currentLine, int $lineNumber, Script $script): string { |
||
| 102 | $definition = $this->removeFromStart(self::TOKEN_TEMPLATE, $currentLine); |
||
| 103 | list($rawSource, $rawDestination) = explode(':', $definition); |
||
| 104 | |||
| 105 | $source = $script->getDirectory() . '/' . $rawSource; |
||
| 106 | $destination = $script->getDirectory() . '/' . $rawDestination; |
||
| 107 | |||
| 108 | $this->commandBuilder |
||
| 109 | ->addTemplateCommand($source, $destination, $lineNumber); |
||
| 110 | |||
| 111 | return ''; |
||
| 112 | }, |
||
| 113 | |||
| 114 | self::TOKEN_WAIT => function (string $currentLine, int $lineNumber): string { |
||
| 115 | $this->commandBuilder |
||
| 116 | ->addWaitCommand($lineNumber); |
||
| 117 | |||
| 118 | |||
| 119 | return ''; |
||
| 120 | }, |
||
| 121 | |||
| 122 | self::TOKEN_MODIFIER_IGNORE_ERROR => function (string $currentLine): string { |
||
| 123 | $this->commandBuilder->setIgnoreError(); |
||
| 124 | |||
| 125 | return $this->removeFromStart(self::TOKEN_MODIFIER_IGNORE_ERROR, $currentLine); |
||
| 126 | }, |
||
| 127 | |||
| 128 | self::TOKEN_MODIFIER_TTY => function (string $currentLine): string { |
||
| 129 | $this->commandBuilder->setTty(); |
||
| 130 | |||
| 131 | return $this->removeFromStart(self::TOKEN_MODIFIER_TTY, $currentLine); |
||
| 132 | }, |
||
| 133 | |||
| 134 | self::TOKEN_MODIFIER_DEFERRED => function (string $currentLine): string { |
||
| 135 | $this->commandBuilder->setDeferredExecution(); |
||
| 136 | |||
| 137 | return $this->removeFromStart(self::TOKEN_MODIFIER_DEFERRED, $currentLine); |
||
| 138 | }, |
||
| 139 | |||
| 140 | self::TOKEN_WILDCARD => function (string $currentLine, int $lineNumber): string { |
||
| 141 | $this->commandBuilder |
||
| 142 | ->addProcessCommand($currentLine, $lineNumber); |
||
| 143 | |||
| 144 | return ''; |
||
| 145 | }, |
||
| 146 | ]; |
||
| 147 | } |
||
| 148 | |||
| 235 |