| Conditions | 3 |
| Paths | 3 |
| Total Lines | 58 |
| Code Lines | 37 |
| 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 |
||
| 49 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 50 | { |
||
| 51 | $username = $input->getArgument('username'); |
||
| 52 | $password = $input->getArgument('password'); |
||
| 53 | $email = $input->getArgument('email'); |
||
| 54 | $gender = $input->getArgument('gender'); |
||
| 55 | |||
| 56 | $output->write('Создание персонажа ... '); |
||
| 57 | |||
| 58 | $container = $this->getContainer(); |
||
| 59 | |||
| 60 | $userManager = $container->get('fos_user.user_manager'); |
||
| 61 | $humanRepository = $container->get('kingdom.human_repository'); |
||
| 62 | $userService = $container->get('kingdom.user_service'); |
||
| 63 | |||
| 64 | /** @var User $user */ |
||
| 65 | $user = $userManager->createUser(); |
||
| 66 | $user->setUsername($username); |
||
| 67 | $user->setEmail($email); |
||
| 68 | $userManager->updateCanonicalFields($user); |
||
| 69 | |||
| 70 | $cyrillicName = $userService->transliterate($user->getUsernameCanonical()); |
||
| 71 | |||
| 72 | if ($this->checkUserExist($humanRepository, $username, $cyrillicName, $email)) { |
||
| 73 | $output->writeln('персонаж уже существует.'); |
||
| 74 | } else { |
||
| 75 | $user->setPlainPassword($password); |
||
| 76 | $userManager->updatePassword($user); |
||
| 77 | |||
| 78 | $user->setEnabled(true); |
||
| 79 | $user->setAvatar($userService->pickAvatar()); |
||
| 80 | $user->setName($cyrillicName); |
||
| 81 | $user->setRoom($userService->getStartRoom()); |
||
| 82 | |||
| 83 | // мужской пол по умолчанию |
||
| 84 | if ($gender === User::GENDER_FEMALE) { |
||
| 85 | $user->setGender(User::GENDER_FEMALE); |
||
| 86 | } |
||
| 87 | |||
| 88 | $this->createMoney($user, $container); |
||
| 89 | |||
| 90 | $humanRepository->persist($user); |
||
| 91 | $humanRepository->flush($user); |
||
| 92 | |||
| 93 | $output->writeln('персонаж создан!'); |
||
| 94 | |||
| 95 | $output->writeln('===================================='); |
||
| 96 | $output->writeln('Логин: ' . $username); |
||
| 97 | $output->writeln('Пароль: ' . $password); |
||
| 98 | $output->writeln('E-mail: ' . $email); |
||
| 99 | $output->writeln('===================================='); |
||
| 100 | |||
| 101 | /** @var RegistrationLogger $logger */ |
||
| 102 | $logger = $container->get('user.logger.registration'); |
||
| 103 | |||
| 104 | $logger->logRegistration($user); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 143 |