| Conditions | 9 |
| Paths | 14 |
| Total Lines | 53 |
| Code Lines | 42 |
| 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 |
||
| 23 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 24 | { |
||
| 25 | $userManager = $this->getUserManager(); |
||
| 26 | $questionHelper = $this->getQuestionHelper(); |
||
| 27 | |||
| 28 | $user = $this->selectUser($input, $output); |
||
| 29 | |||
| 30 | $fields = [ |
||
| 31 | self::FIELD_REAL_NAME, |
||
| 32 | 'Email', |
||
| 33 | 'Role', |
||
| 34 | self::FIELD_PASSWORD, |
||
| 35 | 'Github Login', |
||
| 36 | 'Google Login', |
||
| 37 | 'Done' |
||
| 38 | ]; |
||
| 39 | |||
| 40 | $fieldQuestion = new ChoiceQuestion( |
||
| 41 | 'Select Field: ', |
||
| 42 | $fields |
||
| 43 | ); |
||
| 44 | do { |
||
| 45 | $this->printUser($user, $output); |
||
| 46 | $field = $questionHelper->ask($input, $output, $fieldQuestion); |
||
| 47 | switch ($field) { |
||
| 48 | case self::FIELD_REAL_NAME: |
||
| 49 | $user = $this->editRealName($input, $output, $user, $questionHelper); |
||
| 50 | break; |
||
| 51 | case 'Email': |
||
| 52 | $user = $this->editEmail($input, $output, $user, $questionHelper); |
||
| 53 | break; |
||
| 54 | case 'Role': |
||
| 55 | $user = $this->editRole($input, $output, $user, $questionHelper); |
||
| 56 | break; |
||
| 57 | case self::FIELD_PASSWORD: |
||
| 58 | $user = $this->editPassword($input, $output, $user, $questionHelper, $userManager); |
||
| 59 | break; |
||
| 60 | case 'Github Login': |
||
| 61 | $user = $this->editGithubId($input, $output, $user, $questionHelper); |
||
| 62 | break; |
||
| 63 | case 'Google Login': |
||
| 64 | $user = $this->editGoogleId($input, $output, $user, $questionHelper); |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | } while ('Done' !== $field); |
||
| 68 | |||
| 69 | $this->printUser($user, $output); |
||
| 70 | |||
| 71 | $saveQuestion = new ConfirmationQuestion('Save? ', false); |
||
| 72 | if ($questionHelper->ask($input, $output, $saveQuestion)) { |
||
| 73 | $userManager->updateUser($user); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 |