Completed
Push — main ( fffb13...d8afdd )
by Laurent
139:07 queued 124:29
created

EmailField::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Domain\Model\Common\VO;
6
7
use Domain\Model\Common\InvalidEmail;
8
9
final class EmailField
10
{
11
    /**
12
     * @var string
13
     */
14
    private $email;
15
16
    /**
17
     * Email constructor.
18
     * @param string $email
19
     */
20
    public function __construct(string $email)
21
    {
22
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
23
            throw new InvalidEmail();
24
        }
25
        $this->email = $email;
26
    }
27
28
    public static function fromString(string $email): self
29
    {
30
        return new self($email);
31
    }
32
33
    public function getValue(): string
34
    {
35
        return $this->email;
36
    }
37
}
38