| Conditions | 12 |
| Paths | 12 |
| Total Lines | 55 |
| Code Lines | 37 |
| 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 |
||
| 80 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
| 81 | $key = $input->getArgument('key'); |
||
| 82 | $value = $input->getArgument('value'); |
||
| 83 | |||
| 84 | if ($key === null) { |
||
| 85 | $output->writeln('Current theming config:'); |
||
| 86 | foreach (self::SUPPORTED_KEYS as $key) { |
||
| 87 | $value = $this->config->getAppValue('theming', $key, ''); |
||
| 88 | $output->writeln('- ' . $key . ': ' . $value . ''); |
||
| 89 | } |
||
| 90 | foreach (self::SUPPORTED_IMAGE_KEYS as $key) { |
||
| 91 | $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
||
| 92 | $output->writeln('- ' . $key . ': ' . $value . ''); |
||
| 93 | } |
||
| 94 | return 0; |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
||
| 98 | $output->writeln('<error>Invalid config key provided</error>'); |
||
| 99 | return 1; |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($input->getOption('reset')) { |
||
| 103 | $defaultValue = $this->themingDefaults->undo($key); |
||
| 104 | $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
||
|
|
|||
| 105 | return 0; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($value === null) { |
||
| 109 | $value = $this->config->getAppValue('theming', $key, ''); |
||
| 110 | if ($value !== '') { |
||
| 111 | $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
||
| 112 | } else { |
||
| 113 | $output->writeln('<info>' . $key . ' is currently not set</info>'); |
||
| 114 | } |
||
| 115 | return 0; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) { |
||
| 119 | if (strpos($value, '/') !== 0) { |
||
| 120 | $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
||
| 121 | return 1; |
||
| 122 | } |
||
| 123 | if (!file_exists($value)) { |
||
| 124 | $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
||
| 125 | return 1; |
||
| 126 | } |
||
| 127 | $value = $this->imageManager->updateImage($key, $value); |
||
| 128 | $key = $key . 'Mime'; |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->themingDefaults->set($key, $value); |
||
| 132 | $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
||
| 133 | |||
| 134 | return 0; |
||
| 135 | } |
||
| 137 |