Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Email
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 createRandom
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 convert
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\CommonValueObjects;
3
4use Apie\Core\Attributes\CmsSingleInput;
5use Apie\Core\Attributes\CmsValidationCheck;
6use Apie\Core\Attributes\FakeMethod;
7use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
8use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
9use Apie\Core\ValueObjects\IsStringValueObject;
10use Egulias\EmailValidator\EmailValidator;
11use Egulias\EmailValidator\Validation\RFCValidation;
12use Faker\Generator;
13use ReflectionClass;
14
15#[FakeMethod('createRandom')]
16#[CmsSingleInput(['email', 'text'])]
17#[CmsValidationCheck(pattern: '^[^@]+@[^@]+$')]
18class 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}