| Conditions | 4 |
| Paths | 3 |
| Total Lines | 41 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | 4 | public function create( |
|
| 28 | Interactor $io, |
||
| 29 | string $username, |
||
| 30 | ): void { |
||
| 31 | 4 | $user = $this->userRepository->findOneBy([ |
|
| 32 | 'name' => $username, |
||
| 33 | ]); |
||
| 34 | |||
| 35 | 4 | if ($user !== null) { |
|
| 36 | 1 | $io->error('A user with that name already exists', true); |
|
| 37 | 1 | return; |
|
| 38 | } |
||
| 39 | |||
| 40 | 3 | $validator = function ($password): string { |
|
| 41 | 2 | $password = trim((string) $password); |
|
| 42 | 2 | if (mb_strlen($password) < PasswordVerificator::PASSWORD_MIN_LENGTH) { |
|
| 43 | 1 | throw new InvalidArgumentException('Password too short'); |
|
| 44 | } |
||
| 45 | |||
| 46 | 1 | return $password; |
|
| 47 | }; |
||
| 48 | |||
| 49 | 3 | $password = $io->promptHidden('Password', $validator, self::PASSWORD_RETRIES); |
|
| 50 | |||
| 51 | 2 | if ($password === '') { |
|
| 52 | 1 | $io->error('Too many retries - aborting', true); |
|
| 53 | 1 | return; |
|
| 54 | } |
||
| 55 | |||
| 56 | 1 | $user = $this->userCreator->create( |
|
| 57 | $username, |
||
| 58 | $password |
||
| 59 | ); |
||
| 60 | |||
| 61 | 1 | $io->info( |
|
| 62 | 1 | sprintf( |
|
| 63 | 'Created user `%s` with id `%d`', |
||
| 64 | $username, |
||
| 65 | 1 | $user->getId() |
|
| 66 | ), |
||
| 67 | true |
||
| 68 | ); |
||
| 71 |