| Conditions | 12 |
| Paths | 32 |
| Total Lines | 99 |
| Lines | 32 |
| Ratio | 32.32 % |
| 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 |
||
| 160 | protected function interact(InputInterface $input, OutputInterface $output) |
||
| 161 | { |
||
| 162 | View Code Duplication | if (!$input->getArgument('username')) { |
|
| 163 | $question = New Question('Please choose a username:'); |
||
| 164 | $question->setValidator(function ($username) { |
||
| 165 | if (null === $username) { |
||
| 166 | throw new \InvalidArgumentException('Username can not be empty'); |
||
| 167 | } |
||
| 168 | |||
| 169 | return $username; |
||
| 170 | }); |
||
| 171 | $username = $this->getHelper('question')->ask( |
||
| 172 | $input, |
||
| 173 | $output, |
||
| 174 | $question |
||
| 175 | ); |
||
| 176 | $input->setArgument('username', $username); |
||
| 177 | } |
||
| 178 | |||
| 179 | View Code Duplication | if (!$input->getArgument('email')) { |
|
| 180 | $question = New Question('Please choose an email:'); |
||
| 181 | $question->setValidator(function ($email) { |
||
| 182 | if (null === $email) { |
||
| 183 | throw new \InvalidArgumentException('Email can not be empty'); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $email; |
||
| 187 | }); |
||
| 188 | $email = $this->getHelper('question')->ask( |
||
| 189 | $input, |
||
| 190 | $output, |
||
| 191 | $question |
||
| 192 | ); |
||
| 193 | $input->setArgument('email', $email); |
||
| 194 | } |
||
| 195 | |||
| 196 | if (!$input->getArgument('password')) { |
||
| 197 | |||
| 198 | $question = New Question('Please choose a password:'); |
||
| 199 | $question->setHidden(true); |
||
| 200 | $question->setHiddenFallback(false); |
||
| 201 | $question->setValidator(function ($password) { |
||
| 202 | if (null === $password) { |
||
| 203 | throw new \InvalidArgumentException('Password can not be empty'); |
||
| 204 | } |
||
| 205 | |||
| 206 | return $password; |
||
| 207 | }); |
||
| 208 | $password = $this->getHelper('question')->ask( |
||
| 209 | $input, |
||
| 210 | $output, |
||
| 211 | $question |
||
| 212 | ); |
||
| 213 | |||
| 214 | $input->setArgument('password', $password); |
||
| 215 | } |
||
| 216 | |||
| 217 | if (!$input->getArgument('locale')) { |
||
| 218 | $locale = $this->getHelper('question')->ask( |
||
| 219 | $input, |
||
| 220 | $output, |
||
| 221 | new Question('Please enter the locale (or leave empty for default admin locale):') |
||
| 222 | ); |
||
| 223 | $input->setArgument('locale', $locale); |
||
| 224 | } |
||
| 225 | |||
| 226 | if (!$input->getOption('group')) { |
||
| 227 | $question = new ChoiceQuestion( |
||
| 228 | 'Please enter the group(s) the user should be a member of (multiple possible, separated by comma):', |
||
| 229 | $this->groups, |
||
| 230 | '' |
||
| 231 | ); |
||
| 232 | $question->setMultiselect(true); |
||
| 233 | $question->setValidator(function ($groupsInput) { |
||
| 234 | |||
| 235 | if (!$this->groups) { |
||
| 236 | throw new \RuntimeException('No user group(s) could be found'); |
||
| 237 | } |
||
| 238 | |||
| 239 | // Validate that the chosen group options exist in the available groups |
||
| 240 | $groupNames = array_unique(explode(',', $groupsInput)); |
||
| 241 | if (count(array_intersect_key(array_flip($groupNames),$this->groups)) !== count($groupNames)) { |
||
| 242 | throw new InvalidArgumentException('You have chosen non existing group(s)'); |
||
| 243 | } |
||
| 244 | |||
| 245 | if ($groupsInput === '') { |
||
| 246 | throw new \RuntimeException( |
||
| 247 | 'Group(s) must be of type integer and can not be empty' |
||
| 248 | ); |
||
| 249 | } |
||
| 250 | return $groupsInput; |
||
| 251 | }); |
||
| 252 | |||
| 253 | // Group has to be imploded because $input->setOption expects a string |
||
| 254 | $groups = $this->getHelper('question')->ask($input, $output, $question); |
||
| 255 | |||
| 256 | $input->setOption('group', $groups); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 273 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.