| Conditions | 5 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 32 |
| 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 |
||
| 59 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 60 | { |
||
| 61 | /** @var Packagist $packagist */ |
||
| 62 | $packagist = $this->getContainer()->get('wowapps.packagist'); |
||
| 63 | $searchQuery = strtolower($input->getArgument('search_query')); |
||
| 64 | $symfonyStyle = new SymfonyStyle($input, $output); |
||
| 65 | |||
| 66 | echo PHP_EOL; |
||
| 67 | $output->writeln('<bg=green;options=bold;fg=white> </>'); |
||
| 68 | $output->writeln('<bg=green;options=bold;fg=white> Symfony Packagist API Bundle </>'); |
||
| 69 | $output->writeln('<bg=green;options=bold;fg=white> </>'); |
||
| 70 | echo PHP_EOL; |
||
| 71 | |||
| 72 | if (empty($searchQuery)) { |
||
| 73 | $symfonyStyle->error([ |
||
| 74 | PackagistException::E_EMPTY_SEARCH_QUERY, |
||
| 75 | PackagistException::E_EMPTY_SEARCH_QUERY_DESCRIPTION, |
||
| 76 | ]); |
||
| 77 | |||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | $symfonyStyle->title('Search for packages'); |
||
| 82 | |||
| 83 | $packagesList = $packagist->searchPackages( |
||
| 84 | $searchQuery, |
||
| 85 | $input->getOption('tag'), |
||
| 86 | $input->getOption('type') |
||
| 87 | ); |
||
| 88 | |||
| 89 | if (!$packagesList->count()) { |
||
| 90 | $symfonyStyle->warning(PackagistException::W_NO_SEARCH_RESULT); |
||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | $showList = $symfonyStyle->confirm( |
||
| 95 | sprintf('Founded %d packages. Do you want to show them all?', $packagesList->count()), |
||
| 96 | false |
||
| 97 | ); |
||
| 98 | |||
| 99 | if ($showList) { |
||
| 100 | foreach ($packagesList as $package) { |
||
| 101 | $output->writeln( |
||
| 102 | sprintf( |
||
| 103 | '<options=bold;fg=yellow>%s</>%s', |
||
| 104 | $package->getName(), |
||
| 105 | PHP_EOL . $package->getDescription() . PHP_EOL |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 |