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