| Conditions | 10 |
| Paths | 170 |
| Total Lines | 67 |
| 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 |
||
| 57 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 58 | { |
||
| 59 | $new_map = MapHandler::map('\FileEye\MimeMap\Map\EmptyMap'); |
||
| 60 | $updater = new MapUpdater($new_map); |
||
| 61 | |||
| 62 | // Executes on an emtpy map the script commands. |
||
| 63 | $commands = Yaml::parse(file_get_contents($input->getOption('script'))); |
||
| 64 | foreach ($commands as $command) { |
||
| 65 | $output->writeln("<info>{$command[0]} ...</info>"); |
||
| 66 | try { |
||
| 67 | $errors = call_user_func_array([$updater, $command[1]], $command[2]); |
||
| 68 | if (!empty($errors)) { |
||
| 69 | foreach ($errors as $error) { |
||
| 70 | $output->writeln("<comment>$error.</comment>"); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } catch (\Exception $e) { |
||
| 74 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 75 | exit(2); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | MapHandler::setDefaultMapClass($input->getOption('class')); |
||
| 80 | $current_map = MapHandler::map(); |
||
| 81 | |||
| 82 | // Check if anything got changed. |
||
| 83 | $write = true; |
||
| 84 | if ($input->getOption('diff')) { |
||
| 85 | $write = false; |
||
|
|
|||
| 86 | try { |
||
| 87 | $output->writeln("<info>Checking changes to MIME types ...</info>"); |
||
| 88 | $this->compareMaps($current_map, $new_map, 't'); |
||
| 89 | } catch (\RuntimeException $e) { |
||
| 90 | $output->writeln('<comment>Changes to MIME types mapping:</comment>'); |
||
| 91 | $output->writeln($e->getMessage()); |
||
| 92 | $write = true; |
||
| 93 | } |
||
| 94 | $write = false; |
||
| 95 | try { |
||
| 96 | $output->writeln("<info>Checking changes to MIME type aliases ...</info>"); |
||
| 97 | $this->compareMaps($current_map, $new_map, 'a'); |
||
| 98 | } catch (\RuntimeException $e) { |
||
| 99 | $output->writeln('<comment>Changes to MIME types aliases:</comment>'); |
||
| 100 | $output->writeln($e->getMessage()); |
||
| 101 | $write = true; |
||
| 102 | } |
||
| 103 | try { |
||
| 104 | $output->writeln("<info>Checking changes to extensions ...</info>"); |
||
| 105 | $this->compareMaps($current_map, $new_map, 'e'); |
||
| 106 | } catch (\RuntimeException $e) { |
||
| 107 | $output->writeln('<comment>Changes to extensions mapping</comment>'); |
||
| 108 | $output->writeln($e->getMessage()); |
||
| 109 | $write = true; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | // If changed, save the new map to the PHP file. |
||
| 114 | if ($write) { |
||
| 115 | $updater->writeMapToPhpClassFile($current_map->getFileName()); |
||
| 116 | $output->writeln('<comment>Code updated.</comment>'); |
||
| 117 | } else { |
||
| 118 | $output->writeln('<info>No changes to mapping.</info>'); |
||
| 119 | } |
||
| 120 | |||
| 121 | // Reset the new map's map array. |
||
| 122 | $new_map->reset(); |
||
| 123 | } |
||
| 124 | |||
| 164 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.