| Conditions | 8 |
| Paths | 14 |
| Total Lines | 62 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 19 | protected function runCommand(Command|string $command, array $userParameters = []): int |
||
| 20 | { |
||
| 21 | if (is_string($command)) { |
||
| 22 | $commandIdentifier = $command; |
||
| 23 | $command = $this->getCommand($command); |
||
| 24 | } else { |
||
| 25 | $commandIdentifier = $command->getFullyQualifiedIdentifier(); |
||
| 26 | } |
||
| 27 | |||
| 28 | $repositoryIdentifier = RepositoryCollection::getRepositoryIdentifier($commandIdentifier); |
||
| 29 | |||
| 30 | /** @var QuestionHelper $questionHelper */ |
||
| 31 | $questionHelper = $this->getHelper('question'); |
||
| 32 | |||
| 33 | $promptHelper = new PromptHelper($this->getInput(), $this->getOutput(), $questionHelper, $this->getRecentParameterMemory()); |
||
| 34 | |||
| 35 | $prompt = $promptHelper->askForPrompt($command, $userParameters); |
||
| 36 | |||
| 37 | $promptHelper->showFinalPrompt($prompt); |
||
| 38 | |||
| 39 | $runHelper = new RunHelper($this->getInput(), $this->getOutput(), $questionHelper, $this->getConfigHandler(), $this->getHistoryHandler()); |
||
| 40 | |||
| 41 | $force = $this->getInput()->getOption('force'); |
||
| 42 | |||
| 43 | if (!$runHelper->handleRunnable($command, $prompt->getFinalPrompt())) { |
||
| 44 | return SymfonyCommand::SUCCESS; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!$runHelper->handleForceOption($force, $command, $repositoryIdentifier)) { |
||
| 48 | return SymfonyCommand::FAILURE; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (!$runHelper->confirmRun($force)) { |
||
| 52 | return SymfonyCommand::FAILURE; |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->getOutput()->writeln(''); |
||
| 56 | |||
| 57 | try { |
||
| 58 | $exitCode = $runHelper->executeCommand($this->getOutput(), $command, $prompt); |
||
| 59 | } catch (ToolNotFoundException $exception) { |
||
| 60 | if ($command->getFullyQualifiedIdentifier()) { |
||
| 61 | $this->getRepositoryCollection()->pushStatus($command->getFullyQualifiedIdentifier(), StatusAwareRepository::STATUS_FAILURE); |
||
| 62 | } |
||
| 63 | $this->renderErrorBox($exception->getMessage()); |
||
| 64 | return SymfonyCommand::FAILURE; |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->getOutput()->writeln(''); |
||
| 68 | |||
| 69 | if ($exitCode == SymfonyCommand::SUCCESS) { |
||
| 70 | $this->getOutput()->writeln('<info>Command ran successfully.'); |
||
| 71 | } else { |
||
| 72 | $this->getOutput()->writeln('<error>' . $exitCode . ' Command did not run successfully.'); |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->getConfigHandler()->persistChecksum($command, $repositoryIdentifier); |
||
| 76 | $this->getRecentParameterMemory()->dump(); |
||
| 77 | |||
| 78 | $this->getRepositoryCollection()->pushStatus($command->getFullyQualifiedIdentifier(), StatusAwareRepository::STATUS_SUCCESS); |
||
| 79 | |||
| 80 | return SymfonyCommand::SUCCESS; |
||
| 81 | } |
||
| 83 |