Passed
Pull Request — main (#8)
by Alex
03:11 queued 01:35
created

Email::checkValueIsAValidEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace StraTDeS\VO\Single;
4
5
class Email
6
{
7
    private string $value;
8
9 6
    private function __construct(string $value)
10
    {
11 6
        $this->checkValueIsAValidEmail($value);
12 5
        $this->value = $value;
13 5
    }
14
15 6
    public static function fromValue(string $value): Email
16
    {
17 6
        return new Email($value);
18
    }
19
20 1
    public function value(): string
21
    {
22 1
        return $this->value;
23
    }
24
25 6
    private function checkValueIsAValidEmail(string $value): void
26
    {
27 6
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
28 1
            throw new \InvalidArgumentException("$value is not a valid email");
29
        }
30 5
    }
31
32 2
    public function equal(Email $email): bool
33
    {
34 2
        return $this->value == $email->value;
35
    }
36
}
37