| Conditions | 26 |
| Paths | 21 |
| Total Lines | 85 |
| Code Lines | 63 |
| 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 |
||
| 161 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
| 162 | try { |
||
| 163 | $this->checkInput($input); |
||
| 164 | } catch (\InvalidArgumentException $e) { |
||
| 165 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 166 | return 1; |
||
| 167 | } |
||
| 168 | |||
| 169 | $uid = $input->getArgument('uid'); |
||
| 170 | $app = $input->getArgument('app'); |
||
| 171 | $key = $input->getArgument('key'); |
||
| 172 | |||
| 173 | if ($key !== '') { |
||
| 174 | $value = $this->config->getUserValue($uid, $app, $key, null); |
||
| 175 | if ($input->getArgument('value') !== null) { |
||
| 176 | if ($input->hasParameterOption('--update-only') && $value === null) { |
||
| 177 | $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
||
| 178 | return 1; |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($app === 'settings' && in_array($key , ['email', 'display_name'])) { |
||
| 182 | $user = $this->userManager->get($uid); |
||
| 183 | if ($user instanceof IUser) { |
||
| 184 | if ($key === 'email') { |
||
| 185 | $user->setEMailAddress($input->getArgument('value')); |
||
| 186 | } elseif ($key === 'display_name') { |
||
| 187 | if (!$user->setDisplayName($input->getArgument('value'))) { |
||
| 188 | if ($user->getDisplayName() === $input->getArgument('value')) { |
||
| 189 | $output->writeln('<error>New and old display name are the same</error>'); |
||
| 190 | } elseif ($input->getArgument('value') === '') { |
||
| 191 | $output->writeln('<error>New display name can\'t be empty</error>'); |
||
| 192 | } else { |
||
| 193 | $output->writeln('<error>Could not set display name</error>'); |
||
| 194 | } |
||
| 195 | return 1; |
||
| 196 | } |
||
| 197 | } |
||
| 198 | // setEmailAddress and setDisplayName both internally set the value |
||
| 199 | return 0; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | $this->config->setUserValue($uid, $app, $key, $input->getArgument('value')); |
||
| 204 | return 0; |
||
| 205 | } elseif ($input->hasParameterOption('--delete')) { |
||
| 206 | if ($input->hasParameterOption('--error-if-not-exists') && $value === null) { |
||
| 207 | $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
||
| 208 | return 1; |
||
| 209 | } |
||
| 210 | |||
| 211 | if ($app === 'settings' && in_array($key , ['email', 'display_name'])) { |
||
| 212 | $user = $this->userManager->get($uid); |
||
| 213 | if ($user instanceof IUser) { |
||
| 214 | if ($key === 'email') { |
||
| 215 | $user->setEMailAddress(''); |
||
| 216 | // setEmailAddress already deletes the value |
||
| 217 | return 0; |
||
| 218 | } elseif ($key === 'display_name') { |
||
| 219 | $output->writeln('<error>Display name can\'t be deleted.</error>'); |
||
| 220 | return 1; |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | $this->config->deleteUserValue($uid, $app, $key); |
||
| 226 | return 0; |
||
| 227 | } elseif ($value !== null) { |
||
| 228 | $output->writeln($value); |
||
| 229 | return 0; |
||
| 230 | } elseif ($input->hasParameterOption('--default-value')) { |
||
| 231 | $output->writeln($input->getOption('default-value')); |
||
| 232 | return 0; |
||
| 233 | } else { |
||
| 234 | if ($app === 'settings' && $key === 'display_name') { |
||
| 235 | $user = $this->userManager->get($uid); |
||
| 236 | $output->writeln($user->getDisplayName()); |
||
| 237 | return 0; |
||
| 238 | } |
||
| 239 | $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); |
||
| 240 | return 1; |
||
| 241 | } |
||
| 242 | } else { |
||
| 243 | $settings = $this->getUserSettings($uid, $app); |
||
| 244 | $this->writeArrayInOutputFormat($input, $output, $settings); |
||
| 245 | return 0; |
||
| 246 | } |
||
| 273 |