Passed
Push — 1.0.0 ( 681a4e...b8a5a2 )
by Alex
01:34
created

Email   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 3 1
A fromValue() 0 3 1
A checkValueIsAValidEmail() 0 4 2
A __construct() 0 4 1
1
<?php
2
3
namespace StraTDeS\VO;
4
5
class Email
6
{
7
    private string $value;
8
9 2
    private function __construct(string $value)
10
    {
11 2
        $this->checkValueIsAValidEmail($value);
12 1
        $this->value = $value;
13 1
    }
14
15 2
    public static function fromValue(string $value): Email
16
    {
17 2
        return new Email($value);
18
    }
19
20 1
    public function value(): string
21
    {
22 1
        return $this->value;
23
    }
24
25 2
    private function checkValueIsAValidEmail(string $value): void
26
    {
27 2
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
28 1
            throw new \InvalidArgumentException("$value is not a valid email");
29
        }
30 1
    }
31
}
32