| Conditions | 10 |
| Paths | 12 |
| Total Lines | 56 |
| Code Lines | 37 |
| 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); |
||
| 63 | public function run(array $inputArgs): int |
||
| 64 | { |
||
| 65 | $config = $this->applicationFactory |
||
| 66 | ->createConfig($this->rootDirectory); |
||
| 67 | |||
| 68 | $scriptFinder = $this->applicationFactory |
||
| 69 | ->createScriptFinder($config); |
||
| 70 | |||
| 71 | $this->printHeader($config); |
||
| 72 | $scriptNames = $this->extractScriptNames($inputArgs); |
||
| 73 | if (count($scriptNames) > 0 && $scriptNames[0] === 'bash_autocompletion_dump') { |
||
| 74 | $scripts = $scriptFinder->getAllScripts(); |
||
| 75 | $commands = array_map(function (Script $script) { |
||
| 76 | return $script->getName(); |
||
| 77 | }, $scripts); |
||
| 78 | echo implode(' ', $commands); |
||
| 79 | return self::RESULT_SUCCESS; |
||
| 80 | } |
||
| 81 | |||
| 82 | try { |
||
| 83 | foreach ($scriptNames as $scriptName) { |
||
| 84 | $executionExitCode = $this->execute($scriptFinder->findScriptByName($scriptName), $config); |
||
| 85 | |||
| 86 | if ($executionExitCode !== self::RESULT_SUCCESS) { |
||
| 87 | return $executionExitCode; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if (isset($executionExitCode)) { |
||
| 92 | return $executionExitCode; |
||
| 93 | } |
||
| 94 | } catch (ScriptNotFoundException $e) { |
||
| 95 | $this->notifyError("Script with name {$inputArgs[1]} not found\n"); |
||
| 96 | |||
| 97 | $scripts = []; |
||
| 98 | foreach ($scriptNames as $scriptName) { |
||
| 99 | $newScripts = $scriptFinder->findScriptsByPartialName($scriptName); |
||
| 100 | $scripts = array_merge($scripts, $newScripts); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (count($scripts) > 0) { |
||
| 104 | $this->cliMate->yellow()->bold('Have you been looking for this?'); |
||
| 105 | $this->showListing($scripts); |
||
| 106 | } |
||
| 107 | return self::RESULT_ERROR; |
||
| 108 | } |
||
| 109 | |||
| 110 | try { |
||
| 111 | $this->showListing($scriptFinder->getAllScripts()); |
||
| 112 | } catch (ScriptPathNotValidException $e) { |
||
| 113 | $this->notifyError($e->getMessage() . "\n"); |
||
| 114 | return self::RESULT_ERROR; |
||
| 115 | } |
||
| 116 | |||
| 117 | return self::RESULT_SUCCESS; |
||
| 118 | } |
||
| 119 | |||
| 235 |