| Conditions | 10 |
| Paths | 12 |
| Total Lines | 36 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 50 | public function execute(InputInterface $input, OutputInterface $output): int { |
||
| 51 | $fileInput = $input->getArgument('file'); |
||
| 52 | $outputName = $input->getArgument('output'); |
||
| 53 | $node = $this->fileUtils->getNode($fileInput); |
||
| 54 | |||
| 55 | if (!$node) { |
||
| 56 | $output->writeln("<error>file $fileInput not found</error>"); |
||
| 57 | return 1; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($node instanceof File) { |
||
| 61 | $isTTY = stream_isatty(STDOUT); |
||
| 62 | if ($outputName === null && $isTTY && $node->getMimePart() !== 'text') { |
||
| 63 | $output->writeln([ |
||
| 64 | "<error>Warning: Binary output can mess up your terminal</error>", |
||
| 65 | " Use <info>occ files:get $fileInput -</info> to output it to the terminal anyway", |
||
| 66 | " Or <info>occ files:get $fileInput <FILE></info> to save to a file instead" |
||
| 67 | ]); |
||
| 68 | return 1; |
||
| 69 | } |
||
| 70 | $source = $node->fopen('r'); |
||
| 71 | if (!$source) { |
||
|
|
|||
| 72 | $output->writeln("<error>Failed to open $fileInput for reading</error>"); |
||
| 73 | return 1; |
||
| 74 | } |
||
| 75 | $target = ($outputName === null || $outputName === '-') ? STDOUT : fopen($outputName, 'w'); |
||
| 76 | if (!$target) { |
||
| 77 | $output->writeln("<error>Failed to open $outputName for reading</error>"); |
||
| 78 | return 1; |
||
| 79 | } |
||
| 80 | |||
| 81 | stream_copy_to_stream($source, $target); |
||
| 82 | return 0; |
||
| 83 | } else { |
||
| 84 | $output->writeln("<error>$fileInput is a directory</error>"); |
||
| 85 | return 1; |
||
| 86 | } |
||
| 90 |