| Conditions | 10 |
| Paths | 46 |
| Total Lines | 44 |
| 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 |
||
| 68 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 69 | { |
||
| 70 | $logger = new ConsoleLogger($output); |
||
| 71 | $version = Versions::getVersionFromText($input->getOption('layer')); |
||
| 72 | if ($input->getOption('prefer-stable')) { |
||
| 73 | $version = Versions::STABLE; |
||
| 74 | } |
||
| 75 | $logger->info('Using version: ' . $version); |
||
| 76 | try { |
||
| 77 | $output->writeln('Fetching data for version...'); |
||
| 78 | $generator = TgScraper::fromVersion($logger, $version); |
||
| 79 | } catch (Throwable $e) { |
||
| 80 | $logger->critical((string)$e); |
||
| 81 | return Command::FAILURE; |
||
| 82 | } |
||
| 83 | $output->writeln('Exporting schema from data...'); |
||
| 84 | $destination = $input->getArgument('destination'); |
||
| 85 | try { |
||
| 86 | TgScraper::getTargetDirectory(pathinfo($destination)['dirname']); |
||
| 87 | } catch (Exception) { |
||
| 88 | return Command::FAILURE; |
||
| 89 | } |
||
| 90 | $readable = $input->getOption('readable'); |
||
| 91 | $options = $input->getOption('options'); |
||
| 92 | $useYaml = $input->getOption('yaml'); |
||
| 93 | $inline = $readable ? 16 : $input->getOption('inline'); |
||
| 94 | $indent = $readable ? 4 : $input->getOption('indent'); |
||
| 95 | $output->writeln('Saving schema to file...'); |
||
| 96 | if ($input->getOption('openapi')) { |
||
| 97 | $data = $generator->toOpenApi(); |
||
| 98 | if ($useYaml) { |
||
| 99 | return $this->saveFile($logger, $output, $destination, Encoder::toYaml($data, $inline, $indent, $options), log: false); |
||
| 100 | } |
||
| 101 | return $this->saveFile($logger, $output, $destination, Encoder::toJson($data, $options | JSON_UNESCAPED_SLASHES, $readable), log: false); |
||
| 102 | } |
||
| 103 | if ($input->getOption('postman')) { |
||
| 104 | $data = $generator->toPostman(); |
||
| 105 | return $this->saveFile($logger, $output, $destination, Encoder::toJson($data, $options, $readable), log: false); |
||
| 106 | } |
||
| 107 | $data = $generator->toArray(); |
||
| 108 | if ($useYaml) { |
||
| 109 | return $this->saveFile($logger, $output, $destination, Encoder::toYaml($data, $inline, $indent, $options), log: false); |
||
| 110 | } |
||
| 111 | return $this->saveFile($logger, $output, $destination, Encoder::toJson($data, $options, $readable), log: false); |
||
| 112 | } |
||
| 114 | } |