| Conditions | 12 |
| Paths | 63 |
| Total Lines | 55 |
| Code Lines | 41 |
| 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 |
||
| 31 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 32 | { |
||
| 33 | $source = $input->getArgument('source'); |
||
| 34 | $destination = $input->getArgument('destination'); |
||
| 35 | $path = $input->getOption('path'); |
||
| 36 | if (!in_array($path, ['full', 'relative', 'basename'], true)) { |
||
| 37 | throw new \InvalidArgumentException('Path can not have this value'); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($source === '-') { |
||
| 41 | stream_set_blocking(STDIN, false); |
||
| 42 | $data = stream_get_contents(STDIN); |
||
| 43 | stream_set_blocking(STDIN, true); |
||
| 44 | $data_size = strlen($data); |
||
| 45 | if ($data_size === 0) { |
||
| 46 | throw new \LogicException('Empty input!'); |
||
| 47 | } |
||
| 48 | if (empty($destination)) { |
||
| 49 | throw new \LogicException('Source and destination can not be empty'); |
||
| 50 | } |
||
| 51 | $output->writeln('<info>Read ' . $data_size . ' from input</info>'); |
||
| 52 | } else { |
||
| 53 | $data_size = filesize($source); |
||
|
|
|||
| 54 | } |
||
| 55 | |||
| 56 | if (empty($destination)) { |
||
| 57 | switch ($path) { |
||
| 58 | case 'full': |
||
| 59 | $destination = ltrim(realpath($source), '/'); |
||
| 60 | break; |
||
| 61 | case 'relative': |
||
| 62 | $destination = ltrim($source, '/.'); |
||
| 63 | break; |
||
| 64 | case 'basename': |
||
| 65 | $destination = basename($source); |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $archive = $this->getArchive($input, $output); |
||
| 71 | if ($source === '-') { |
||
| 72 | $added_files = $archive->addFileFromString($destination, $data) ? 1 : 0; |
||
| 73 | } else { |
||
| 74 | $added_files = $archive->addFiles([$destination => $source]); |
||
| 75 | } |
||
| 76 | if ($added_files === 1) { |
||
| 77 | $details = $archive->getFileData($destination); |
||
| 78 | $output->writeln('Added <comment>' . $source . '</comment>(' |
||
| 79 | . implode($this->formatSize($data_size)) . ') as ' |
||
| 80 | . $destination . ' (' |
||
| 81 | . implode($this->formatSize($details->compressedSize)) |
||
| 82 | . ')'); |
||
| 83 | } |
||
| 84 | |||
| 85 | return 0; |
||
| 86 | } |
||
| 88 |