| Conditions | 5 |
| Paths | 5 |
| Total Lines | 63 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 45 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 46 | { |
||
| 47 | /** @var QuestionHelper $questionHelper */ |
||
| 48 | $questionHelper = $this->getHelper('question'); |
||
| 49 | $output |
||
| 50 | ->writeln( |
||
| 51 | [ |
||
| 52 | '<info>Welcome to docker-mailserver!</info>', |
||
| 53 | '<info>This tool will help you to set up the first mail account.</info>', |
||
| 54 | '<info>You just have to answer a few questions.</info>', |
||
| 55 | ] |
||
| 56 | ); |
||
| 57 | |||
| 58 | [$localPart, $domainPart] = $this->getEmailAddress($questionHelper, $input, $output); |
||
| 59 | $password = $this->getPassword($questionHelper, $input, $output); |
||
| 60 | |||
| 61 | $domain = new Domain(); |
||
| 62 | $domain->setName($domainPart); |
||
| 63 | |||
| 64 | $user = new User(); |
||
| 65 | $user->setName($localPart); |
||
| 66 | $user->setPlainPassword($password); |
||
| 67 | $user->setAdmin(true); |
||
| 68 | $user->setDomain($domain); |
||
| 69 | |||
| 70 | $domainValidationList = $this->validator->validate($domain); |
||
| 71 | $userValidationList = $this->validator->validate($user); |
||
| 72 | |||
| 73 | if ($domainValidationList->count() > 0) { |
||
| 74 | foreach ($domainValidationList as $item) { |
||
| 75 | /* @var $item ConstraintViolation */ |
||
| 76 | $output->writeln( |
||
| 77 | sprintf('<error>Domain %s: %s</error>', $item->getPropertyPath(), $item->getMessage()) |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | |||
| 81 | $output->writeln('<error>There were some errors. Please start over again.</error>'); |
||
| 82 | |||
| 83 | return 1; |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($userValidationList->count() > 0) { |
||
| 87 | foreach ($userValidationList as $item) { |
||
| 88 | /* @var $item ConstraintViolation */ |
||
| 89 | $output->writeln( |
||
| 90 | sprintf('<error>User %s: %s</error>', $item->getPropertyPath(), $item->getMessage()) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | $output->writeln('<error>There were some errors. Please start over again.</error>'); |
||
| 95 | |||
| 96 | return 1; |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->manager->getManager()->persist($domain); |
||
| 100 | $this->manager->getManager()->persist($user); |
||
| 101 | |||
| 102 | $this->manager->getManager()->flush(); |
||
| 103 | |||
| 104 | $output->writeln(sprintf('<info>Your new email address %s was successfully created.</info>', $user)); |
||
| 105 | $output->writeln('<info>You can now login using the previously set password.</info>'); |
||
| 106 | |||
| 107 | return 0; |
||
| 108 | } |
||
| 167 |