Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
|
createRandom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
convert | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace Apie\CommonValueObjects; |
3 | |
4 | use Apie\Core\Attributes\CmsSingleInput; |
5 | use Apie\Core\Attributes\CmsValidationCheck; |
6 | use Apie\Core\Attributes\FakeMethod; |
7 | use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException; |
8 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
9 | use Apie\Core\ValueObjects\IsStringValueObject; |
10 | use Egulias\EmailValidator\EmailValidator; |
11 | use Egulias\EmailValidator\Validation\RFCValidation; |
12 | use Faker\Generator; |
13 | use ReflectionClass; |
14 | |
15 | #[FakeMethod('createRandom')] |
16 | #[CmsSingleInput(['email', 'text'])] |
17 | #[CmsValidationCheck(pattern: '^[^@]+@[^@]+$')] |
18 | class Email implements StringValueObjectInterface |
19 | { |
20 | use IsStringValueObject; |
21 | |
22 | public static function createRandom(Generator $generator): self |
23 | { |
24 | return new static($generator->email()); |
25 | } |
26 | |
27 | protected function convert(string $input): string |
28 | { |
29 | return trim($input); |
30 | } |
31 | |
32 | public static function validate(string $input): void |
33 | { |
34 | $validator = new EmailValidator(); |
35 | if (!$validator->isValid($input, new RFCValidation())) { |
36 | throw new InvalidStringForValueObjectException($input, new ReflectionClass(__CLASS__)); |
37 | } |
38 | } |
39 | } |