| Conditions | 11 |
| Paths | 33 |
| Total Lines | 62 |
| Code Lines | 36 |
| 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 |
||
| 71 | protected function interact(InputInterface $input, OutputInterface $output) |
||
| 72 | { |
||
| 73 | if (!$this->getHelperSet()->has('question')) { |
||
| 74 | $this->legacyInteract($input, $output); |
||
| 75 | |||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | $questions = array(); |
||
| 80 | |||
| 81 | if (!$input->getArgument('username')) { |
||
| 82 | $question = new Question('Please choose a username:'); |
||
| 83 | $question->setValidator(function ($username) { |
||
| 84 | if (empty($username)) { |
||
| 85 | throw new \Exception('Username can not be empty'); |
||
| 86 | } |
||
| 87 | |||
| 88 | return $username; |
||
| 89 | }); |
||
| 90 | $questions['username'] = $question; |
||
| 91 | } |
||
| 92 | |||
| 93 | if (!$input->getArgument('email')) { |
||
| 94 | $question = new Question('Please choose an email:'); |
||
| 95 | $question->setValidator(function ($email) { |
||
| 96 | if (empty($email)) { |
||
| 97 | throw new \Exception('Email can not be empty'); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $email; |
||
| 101 | }); |
||
| 102 | $questions['email'] = $question; |
||
| 103 | } |
||
| 104 | |||
| 105 | if (!$input->getArgument('password')) { |
||
| 106 | $question = new Question('Please choose a password:'); |
||
| 107 | $question->setValidator(function ($password) { |
||
| 108 | if (empty($password)) { |
||
| 109 | throw new \Exception('Password can not be empty'); |
||
| 110 | } |
||
| 111 | |||
| 112 | return $password; |
||
| 113 | }); |
||
| 114 | $question->setHidden(true); |
||
| 115 | $questions['password'] = $question; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (!$input->getArgument('name')) { |
||
| 119 | $question = new Question('Please choose a display name:'); |
||
| 120 | $question->setValidator(function ($name) { |
||
| 121 | if (empty($name)) { |
||
| 122 | throw new \Exception('Display name can not be empty'); |
||
| 123 | } |
||
| 124 | |||
| 125 | return $name; |
||
| 126 | }); |
||
| 127 | $questions['name'] = $question; |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ($questions as $name => $question) { |
||
| 131 | $answer = $this->getHelper('question')->ask($input, $output, $question); |
||
| 132 | $input->setArgument($name, $answer); |
||
| 133 | } |
||
| 165 |