| Conditions | 6 |
| Paths | 11 |
| Total Lines | 51 |
| 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 |
||
| 58 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 59 | { |
||
| 60 | MapHandler::setDefaultMapClass($input->getOption('class')); |
||
| 61 | $current_map = MapHandler::map(); |
||
| 62 | $updater = new MapUpdater(); |
||
| 63 | |||
| 64 | // Loads the map from the source file. |
||
| 65 | try { |
||
| 66 | $new_map = $updater->createMapFromSourceFile($input->getOption('source')); |
||
| 67 | } catch (\RuntimeException $e) { |
||
| 68 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 69 | exit(2); |
||
| 70 | } |
||
| 71 | |||
| 72 | // Applies the overrides. |
||
| 73 | try { |
||
| 74 | $content = file_get_contents($input->getOption('override')); |
||
| 75 | $updater->applyOverrides($new_map, Yaml::parse($content)); |
||
| 76 | } catch (\Exception $e) { |
||
| 77 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 78 | exit(2); |
||
| 79 | } |
||
| 80 | |||
| 81 | // Check if anything got changed. |
||
| 82 | $write = false; |
||
| 83 | try { |
||
| 84 | $this->compareMaps($current_map, $new_map, 'types'); |
||
| 85 | } catch (\RuntimeException $e) { |
||
| 86 | $output->writeln('<comment>Changes to MIME types mapping</comment>'); |
||
| 87 | $output->writeln($e->getMessage()); |
||
| 88 | $write = true; |
||
| 89 | } |
||
| 90 | try { |
||
| 91 | $this->compareMaps($current_map, $new_map, 'extensions'); |
||
| 92 | } catch (\RuntimeException $e) { |
||
| 93 | $output->writeln('<comment>Changes to extensions mapping</comment>'); |
||
| 94 | $output->writeln($e->getMessage()); |
||
| 95 | $write = true; |
||
| 96 | } |
||
| 97 | |||
| 98 | // If changed, save the new map to the PHP file. |
||
| 99 | if ($write) { |
||
| 100 | $updater->writeMapToPhpClassFile($new_map, $current_map->getFileName()); |
||
| 101 | $output->writeln('<comment>Code updated.</comment>'); |
||
| 102 | } else { |
||
| 103 | $output->writeln('<info>No changes to mapping.</info>'); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Reset the new map's map array. |
||
| 107 | $new_map->reset(); |
||
| 108 | } |
||
| 109 | |||
| 149 |