Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
11 / 11 |
| UserValidator | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
11 / 11 |
| __construct($emailValidator, $passwordValidator, $userTypeValidator) | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| isValid($user) | |
100.00% |
1 / 1 |
4 | |
100.00% |
7 / 7 |
|||
| <?php | |
| namespace Tdd; | |
| class UserValidator implements IValidator | |
| { | |
| /** @var EmailValidator */ | |
| private $emailValidator; | |
| /** @var PasswordValidator */ | |
| private $passwordValidator; | |
| /** @var UserTypeValidator */ | |
| private $userTypeValidator; | |
| public function __construct($emailValidator, $passwordValidator, $userTypeValidator) | |
| { | |
| $this->emailValidator = $emailValidator; | |
| $this->passwordValidator = $passwordValidator; | |
| $this->userTypeValidator = $userTypeValidator; | |
| } | |
| public function isValid($user) | |
| { | |
| if (!($user instanceof User)) | |
| { | |
| throw new \InvalidArgumentException('Invalid user!'); | |
| } | |
| return | |
| $this->emailValidator->isValid($user->getEmail()) | |
| && $this->passwordValidator->isValid($user->getPassword()) | |
| && $this->userTypeValidator->isValid($user->getType()) | |
| ; | |
| } | |
| } |