| Conditions | 7 |
| Paths | 15 |
| Total Lines | 54 |
| Code Lines | 30 |
| 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 |
||
| 45 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 46 | { |
||
| 47 | $user = new User(); |
||
| 48 | $domain = $this->getDomain($input->getArgument('domain')); |
||
| 49 | |||
| 50 | if (!$domain) { |
||
| 51 | $output->writeln(sprintf('<error>Domain %s was not found.</error>', $input->getArgument('domain'))); |
||
| 52 | |||
| 53 | return 1; |
||
| 54 | } |
||
| 55 | |||
| 56 | $user->setDomain($domain); |
||
| 57 | $user->setName(\mb_strtolower($input->getArgument('name'))); |
||
| 58 | $user->setAdmin((bool)$input->getOption('admin')); |
||
| 59 | $user->setSendOnly((bool)$input->getOption('sendonly')); |
||
| 60 | |||
| 61 | if ($input->hasOption('quota')) { |
||
| 62 | $user->setQuota((int)$input->getOption('quota')); |
||
| 63 | } |
||
| 64 | |||
| 65 | if (!$input->getOption('password')) { |
||
| 66 | /** @var QuestionHelper $helper */ |
||
| 67 | $helper = $this->getHelper('question'); |
||
| 68 | $question = new Question('Password? (hidden)'); |
||
| 69 | $question->setHidden(true); |
||
| 70 | |||
| 71 | $password = $helper->ask($input, $output, $question); |
||
| 72 | |||
| 73 | if (!$password) { |
||
| 74 | $output->writeln('<error>Please set a valid password.</error>'); |
||
| 75 | |||
| 76 | return 1; |
||
| 77 | } |
||
| 78 | |||
| 79 | $user->setPlainPassword($password); |
||
|
|
|||
| 80 | } else { |
||
| 81 | $user->setPlainPassword($input->getOption('password')); |
||
| 82 | } |
||
| 83 | |||
| 84 | $validationResult = $this->validator->validate($user); |
||
| 85 | |||
| 86 | if ($validationResult->count() > 0) { |
||
| 87 | foreach ($validationResult as $item) { |
||
| 88 | /** @var $item ConstraintViolation */ |
||
| 89 | $output->writeln(sprintf('<error>%s: %s</error>', $item->getPropertyPath(), $item->getMessage())); |
||
| 90 | } |
||
| 91 | |||
| 92 | return 1; |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->manager->persist($user); |
||
| 96 | $this->manager->flush(); |
||
| 97 | |||
| 98 | return 0; |
||
| 99 | } |
||
| 106 |