| Conditions | 7 |
| Paths | 7 |
| Total Lines | 81 |
| Code Lines | 62 |
| Lines | 42 |
| Ratio | 51.85 % |
| 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 |
||
| 186 | private function handleUnknownUsers(InputInterface $input, OutputInterface $output, $syncService, $missingAccountsAction, $validActions) { |
||
| 187 | $output->writeln("Analyse unknown users ..."); |
||
| 188 | $p = new ProgressBar($output); |
||
| 189 | $toBeDeleted = $syncService->getNoLongerExistingUsers(function () use ($p) { |
||
| 190 | $p->advance(); |
||
| 191 | }); |
||
| 192 | $p->finish(); |
||
| 193 | $output->writeln(''); |
||
| 194 | $output->writeln(''); |
||
| 195 | |||
| 196 | if (empty($toBeDeleted)) { |
||
| 197 | $output->writeln("No unknown users have been detected."); |
||
| 198 | } else { |
||
| 199 | $output->writeln("Following users are no longer known with the connected backend."); |
||
| 200 | switch ($missingAccountsAction) { |
||
| 201 | View Code Duplication | case 'disable': |
|
|
|
|||
| 202 | $output->writeln("Proceeding to disable the accounts"); |
||
| 203 | $this->doActionForAccountUids($toBeDeleted, |
||
| 204 | function ($uid, IUser $ac) use ($output) { |
||
| 205 | $ac->setEnabled(false); |
||
| 206 | $output->writeln($uid); |
||
| 207 | }, |
||
| 208 | function ($uid) use ($output) { |
||
| 209 | $output->writeln($uid . " (unknown account for the user)"); |
||
| 210 | }); |
||
| 211 | break; |
||
| 212 | View Code Duplication | case 'remove': |
|
| 213 | $output->writeln("Proceeding to remove the accounts"); |
||
| 214 | $this->doActionForAccountUids($toBeDeleted, |
||
| 215 | function ($uid, IUser $ac) use ($output) { |
||
| 216 | $ac->delete(); |
||
| 217 | $output->writeln($uid); |
||
| 218 | }, |
||
| 219 | function ($uid) use ($output) { |
||
| 220 | $output->writeln($uid . " (unknown account for the user)"); |
||
| 221 | }); |
||
| 222 | break; |
||
| 223 | case 'ask later': |
||
| 224 | $output->writeln("listing the unknown accounts"); |
||
| 225 | $this->doActionForAccountUids($toBeDeleted, |
||
| 226 | function ($uid) use ($output) { |
||
| 227 | $output->writeln($uid); |
||
| 228 | }, |
||
| 229 | function ($uid) use ($output) { |
||
| 230 | $output->writeln($uid . " (unknown account for the user)"); |
||
| 231 | }); |
||
| 232 | // overwriting variables! |
||
| 233 | $helper = $this->getHelper('question'); |
||
| 234 | $question = new ChoiceQuestion( |
||
| 235 | 'What do you want to do with their accounts? (removing the account will also remove its data)', |
||
| 236 | $validActions, |
||
| 237 | 0 |
||
| 238 | ); |
||
| 239 | $missingAccountsAction2 = $helper->ask($input, $output, $question); |
||
| 240 | switch ($missingAccountsAction2) { |
||
| 241 | // if "nothing" is selected, just ignore and finish |
||
| 242 | View Code Duplication | case 'disable': |
|
| 243 | $output->writeln("Proceeding to disable the accounts"); |
||
| 244 | $this->doActionForAccountUids($toBeDeleted, |
||
| 245 | function ($uid, IUser $ac) { |
||
| 246 | $ac->setEnabled(false); |
||
| 247 | }, |
||
| 248 | function ($uid) use ($output) { |
||
| 249 | $output->writeln($uid . " (unknown account for the user)"); |
||
| 250 | }); |
||
| 251 | break; |
||
| 252 | View Code Duplication | case 'remove': |
|
| 253 | $output->writeln("Proceeding to remove the accounts"); |
||
| 254 | $this->doActionForAccountUids($toBeDeleted, |
||
| 255 | function ($uid, IUser $ac) { |
||
| 256 | $ac->delete(); |
||
| 257 | }, |
||
| 258 | function ($uid) use ($output) { |
||
| 259 | $output->writeln($uid . " (unknown account for the user)"); |
||
| 260 | }); |
||
| 261 | break; |
||
| 262 | } |
||
| 263 | break; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.