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

EmailField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A fromString() 0 4 1
A getValue() 0 4 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