| Conditions | 8 |
| Paths | 72 |
| Total Lines | 82 |
| Code Lines | 50 |
| 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 |
||
| 25 | protected function execute(InputInterface $input, OutputInterface $output): ?int |
||
| 26 | { |
||
| 27 | $types = Types::getTypes(); |
||
| 28 | |||
| 29 | $question = new Question('<question>Please provide type of packages:</question>' . \PHP_EOL); |
||
| 30 | |||
| 31 | if (method_exists($question, 'setAutocompleterCallback')) { |
||
| 32 | $callback = static function (string $userInput) use ($types): array { |
||
| 33 | return array_filter($types, static function (string $type) use ($userInput) { |
||
| 34 | return false !== mb_stripos($type, $userInput); |
||
| 35 | }); |
||
| 36 | }; |
||
| 37 | $question->setAutocompleterCallback($callback); |
||
| 38 | } else { |
||
| 39 | $question->setAutocompleterValues($types); |
||
| 40 | } |
||
| 41 | |||
| 42 | $helper = $this->getHelper('question'); |
||
| 43 | |||
| 44 | $type = $helper->ask($input, $output, $question) ?? ''; |
||
| 45 | /** @var CompletePackage[] $packages */ |
||
| 46 | $packages = iterator_to_array(Types::get($type)); |
||
| 47 | |||
| 48 | $names = array_map(static function (CompletePackage $completePackage) { |
||
| 49 | return $completePackage->getName(); |
||
| 50 | }, $packages); |
||
| 51 | |||
| 52 | foreach ($packages as $package) { |
||
| 53 | $output->writeln($package->getName()); |
||
| 54 | } |
||
| 55 | |||
| 56 | $question = new Question('<question>Please type the package name you want to explore:</question>' . \PHP_EOL); |
||
| 57 | |||
| 58 | if (method_exists($question, 'setAutocompleterCallback')) { |
||
| 59 | $callback = static function (string $userInput) use ($names): array { |
||
| 60 | return array_filter($names, static function (string $packageName) use ($userInput) { |
||
| 61 | return false !== mb_stripos($packageName, $userInput); |
||
| 62 | }); |
||
| 63 | }; |
||
| 64 | $question->setAutocompleterCallback($callback); |
||
| 65 | } else { |
||
| 66 | $question->setAutocompleterValues($names); |
||
| 67 | } |
||
| 68 | |||
| 69 | $packageName = $helper->ask($input, $output, $question) ?? ''; |
||
| 70 | $package = Packages::get($packageName); |
||
| 71 | |||
| 72 | if (null === $package) { |
||
| 73 | return null; |
||
| 74 | } |
||
| 75 | |||
| 76 | $output->writeln('<fg=green>name </> :' . $package->getName()); |
||
| 77 | $output->writeln('<fg=green>descrip.</> :' . $package->getDescription() ?? '~'); |
||
| 78 | $output->writeln('<fg=green>keywords</> :' . implode(', ', $package->getKeywords() ?? ['~'])); |
||
| 79 | $output->writeln('<fg=green>version </> :' . $package->getVersion() ?? '~'); |
||
| 80 | $output->writeln('<fg=green>type </> :' . $package->getType()); |
||
| 81 | $output->writeln('<fg=green>license </> :' . implode(' ', $package->getLicense() ?? ['~'])); |
||
| 82 | $output->writeln('<fg=green>source </> :[' . $package->getSourceType() . '] ' . $package->getSourceUrl() . ' ' . $package->getSourceReference()); |
||
| 83 | $output->writeln('<fg=green>dist </> :[' . $package->getDistType() . '] ' . $package->getDistUrl() . ' ' . $package->getDistReference()); |
||
| 84 | |||
| 85 | $output->writeln(''); |
||
| 86 | $output->writeln('<fg=green>requires</>'); |
||
| 87 | |||
| 88 | foreach ($package->getRequires() as $link) { |
||
| 89 | $output->writeln($link->getTarget() . ' <fg=yellow>' . $link->getPrettyConstraint() . '</>'); |
||
| 90 | } |
||
| 91 | |||
| 92 | $output->writeln(''); |
||
| 93 | $output->writeln('<fg=green>requires-dev</>'); |
||
| 94 | |||
| 95 | foreach ($package->getDevRequires() as $link) { |
||
| 96 | $output->writeln($link->getTarget() . ' <fg=yellow>' . $link->getPrettyConstraint() . '</>'); |
||
| 97 | } |
||
| 98 | |||
| 99 | $output->writeln(''); |
||
| 100 | $output->writeln('<fg=green>suggest</>'); |
||
| 101 | |||
| 102 | foreach ($package->getSuggests() as $name => $suggest) { |
||
| 103 | $output->writeln("{$name} <fg=yellow>{$suggest}</>"); |
||
| 104 | } |
||
| 105 | |||
| 106 | return 0; |
||
| 107 | } |
||
| 109 |