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