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\Description; |
7 | use Apie\Core\Attributes\FakeMethod; |
8 | use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException; |
9 | use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface; |
10 | use Apie\Core\ValueObjects\IsStringValueObject; |
11 | use Egulias\EmailValidator\EmailValidator; |
12 | use Egulias\EmailValidator\Validation\RFCValidation; |
13 | use Faker\Generator; |
14 | use ReflectionClass; |
15 | |
16 | #[FakeMethod('createRandom')] |
17 | #[CmsSingleInput(['email', 'text'])] |
18 | #[CmsValidationCheck(pattern: '^[^@]+@[^@]+$')] |
19 | #[Description('Represents an e-mail address')] |
20 | class Email implements StringValueObjectInterface |
21 | { |
22 | use IsStringValueObject; |
23 | |
24 | public static function createRandom(Generator $generator): self |
25 | { |
26 | return new static($generator->email()); |
27 | } |
28 | |
29 | protected function convert(string $input): string |
30 | { |
31 | return trim($input); |
32 | } |
33 | |
34 | public static function validate(string $input): void |
35 | { |
36 | $validator = new EmailValidator(); |
37 | if (!$validator->isValid($input, new RFCValidation())) { |
38 | throw new InvalidStringForValueObjectException($input, new ReflectionClass(__CLASS__)); |
39 | } |
40 | } |
41 | } |