Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
13 / 13 |
| RegistrationModule | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
13 / 13 |
| __construct($userRepository, $userValidator, $passwordHasher, $passwordGenerator) | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
| registerLocalUser($email, $password) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| registerExternalUser($email, $type) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| registerUser($email, $password, $type) | |
100.00% |
1 / 1 |
2 | |
100.00% |
6 / 6 |
|||
| <?php | |
| namespace Tdd; | |
| class RegistrationModule | |
| { | |
| /** @var UserValidator */ | |
| private $userValidator; | |
| /** @var UserRepository */ | |
| private $userRepository; | |
| /** @var PasswordHasher */ | |
| private $passwordHasher; | |
| /** @var PasswordGenerator */ | |
| private $passwordGenerator; | |
| public function __construct($userRepository, $userValidator, $passwordHasher, $passwordGenerator) | |
| { | |
| $this->userRepository = $userRepository; | |
| $this->userValidator = $userValidator; | |
| $this->passwordHasher = $passwordHasher; | |
| $this->passwordGenerator = $passwordGenerator; | |
| } | |
| public function registerLocalUser($email, $password) | |
| { | |
| return $this->registerUser($email, $password, 'local'); | |
| } | |
| public function registerExternalUser($email, $type) | |
| { | |
| return $this->registerUser($email, $this->passwordGenerator->generate(), $type); | |
| } | |
| private function registerUser($email, $password, $type) | |
| { | |
| $rawUser = new User($email, $password, $type); | |
| if (!$this->userValidator->isValid($rawUser)) | |
| { | |
| throw new \InvalidArgumentException('User details are invalid!'); | |
| } | |
| $encodedUser = new User($email, $this->passwordHasher->hash($password), $type); | |
| return $this->userRepository->save($encodedUser); | |
| } | |
| } |