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