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