| Conditions | 14 |
| Paths | 98 |
| Total Lines | 69 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 44 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 45 | { |
||
| 46 | $from = $input->getArgument('from'); |
||
| 47 | $type = $input->getOption('type'); |
||
| 48 | $outputFile = $input->getOption('output'); |
||
| 49 | $appendFile = $input->getOption('append'); |
||
| 50 | |||
| 51 | if (!is_array($from)) { |
||
| 52 | $from = (array) $from; |
||
| 53 | } |
||
| 54 | |||
| 55 | if (empty($type)) { |
||
| 56 | $autoDetectedType = self::getFileExt($from[0]); |
||
| 57 | foreach ($from as $fromFile) { |
||
| 58 | $fileExt = self::getFileExt($fromFile); |
||
| 59 | if (strcasecmp($fileExt, $autoDetectedType) !== 0) { |
||
| 60 | $output->writeln('<error>Error: type of input files is not all the same!</error>'); |
||
| 61 | |||
| 62 | return 1; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | $type = $autoDetectedType; |
||
| 67 | } |
||
| 68 | |||
| 69 | if (empty($type)) { |
||
| 70 | $output->writeln('<error>Error: cannot find the type of input file!</error>'); |
||
| 71 | |||
| 72 | return 1; |
||
| 73 | } |
||
| 74 | |||
| 75 | switch (strtolower($type)) { |
||
| 76 | case 'css': |
||
| 77 | $minifier = new CSS(); |
||
| 78 | break; |
||
| 79 | case 'js': |
||
| 80 | $minifier = new JS(); |
||
| 81 | break; |
||
| 82 | default: |
||
| 83 | $output->writeln("<error>Error: Unsupported type: $type</error>"); |
||
| 84 | |||
| 85 | return 3; |
||
| 86 | } |
||
| 87 | |||
| 88 | foreach ($from as $fromFile) { |
||
| 89 | if (!file_exists($fromFile)) { |
||
| 90 | $output->writeln("<error>Error: File '{$fromFile}' not found!</error>"); |
||
| 91 | |||
| 92 | return 2; |
||
| 93 | } |
||
| 94 | $minifier->add($fromFile); |
||
| 95 | } |
||
| 96 | |||
| 97 | $result = $minifier->minify(); |
||
| 98 | |||
| 99 | if (empty($outputFile) && empty($appendFile)) { |
||
| 100 | $output->writeln($result, OutputInterface::OUTPUT_RAW); |
||
| 101 | } else { |
||
| 102 | if (!empty($outputFile)) { |
||
| 103 | file_put_contents($outputFile, $result); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (!empty($appendFile)) { |
||
| 107 | file_put_contents($appendFile, $result, FILE_APPEND); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | return 0; |
||
| 112 | } |
||
| 113 | |||
| 119 |