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