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