| Conditions | 9 |
| Paths | 12 |
| Total Lines | 71 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 33 | protected function doExecute(InputInterface $input, OutputInterface $output): int |
||
| 34 | { |
||
| 35 | $this->enrichRepositories(); |
||
| 36 | |||
| 37 | /** @var QuestionHelper $questionHelper */ |
||
| 38 | $questionHelper = $this->getHelper('question'); |
||
| 39 | |||
| 40 | $destinationRepositoryName = $input->getArgument('destinationRepository'); |
||
| 41 | $sourceRepositoryName = $input->getArgument('sourceRepository'); |
||
| 42 | |||
| 43 | $sourceRepository = $this->getRepositoryCollection()->getRepository($sourceRepositoryName); |
||
| 44 | $destinationRepository = $this->getRepositoryCollection()->getRepository($destinationRepositoryName); |
||
| 45 | |||
| 46 | if (!$sourceRepository instanceof ListAware) { |
||
| 47 | throw new \RuntimeException('The given repository "' . $destinationRepositoryName . '" is not listable.'); |
||
| 48 | } |
||
| 49 | |||
| 50 | if (!$destinationRepository instanceof EditableRepository) { |
||
| 51 | throw new \RuntimeException('The given repository "' . $destinationRepositoryName . '" is read-only.'); |
||
| 52 | } |
||
| 53 | |||
| 54 | $commands = $sourceRepository->getCommands(); |
||
| 55 | |||
| 56 | if (count($commands) == 0) { |
||
| 57 | OutputHelper::writeInfoBox($output, 'No commands found in "' . $sourceRepositoryName . '". Cancelling move command.'); |
||
| 58 | return Command::SUCCESS; |
||
| 59 | } |
||
| 60 | |||
| 61 | OutputHelper::writeInfoBox($output, 'We are moving the following commands to the "' . $destinationRepositoryName . '" repository.'); |
||
| 62 | |||
| 63 | \Startwind\Forrest\Output\OutputHelper::renderCommands($output, $input, $questionHelper, $commands); |
||
| 64 | |||
| 65 | $output->writeln(''); |
||
| 66 | |||
| 67 | $move = $questionHelper->ask($input, $output, new ConfirmationQuestion(' Are you sure you want to move these ' . count($commands) . ' command? (y/n) ', false)); |
||
| 68 | |||
| 69 | if (!$move) { |
||
| 70 | return Command::FAILURE; |
||
| 71 | } |
||
| 72 | |||
| 73 | $prefix = $input->getOption('prefix'); |
||
| 74 | |||
| 75 | if ($prefix) { |
||
| 76 | $prefix = $prefix . RepositoryCollection::COMMAND_SEPARATOR; |
||
| 77 | } |
||
| 78 | |||
| 79 | $progressBar = new ProgressBar($output, count($commands)); |
||
| 80 | |||
| 81 | $output->writeln(''); |
||
| 82 | |||
| 83 | foreach ($commands as $command) { |
||
| 84 | $progressBar->advance(); |
||
| 85 | |||
| 86 | $command->setName($prefix . $command->getName()); |
||
| 87 | $progressBar->setMessage('Moving ' . $prefix . $command->getName()); |
||
| 88 | |||
| 89 | $destinationRepository->addCommand($command); |
||
| 90 | |||
| 91 | if ($sourceRepository instanceof EditableRepository) { |
||
| 92 | if ($input->getOption('removeAfterMove')) { |
||
| 93 | $sourceRepository->removeCommand($command->getName()); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | $progressBar->finish(); |
||
| 99 | $output->writeln(''); |
||
| 100 | |||
| 101 | OutputHelper::writeInfoBox($output, 'Successfully moved ' . count($commands) . ' commands to "' . $destinationRepositoryName . '".'); |
||
| 102 | |||
| 103 | return Command::SUCCESS; |
||
| 104 | } |
||
| 106 |