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\Description;
7use Apie\Core\Attributes\FakeMethod;
8use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
9use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
10use Apie\Core\ValueObjects\IsStringValueObject;
11use Egulias\EmailValidator\EmailValidator;
12use Egulias\EmailValidator\Validation\RFCValidation;
13use Faker\Generator;
14use ReflectionClass;
15
16#[FakeMethod('createRandom')]
17#[CmsSingleInput(['email', 'text'])]
18#[CmsValidationCheck(pattern: '^[^@]+@[^@]+$')]
19#[Description('Represents an e-mail address')]
20class 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}