EmailAddress   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __toString() 0 3 1
A equals() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chinstrap\Core\Objects;
6
7
use Chinstrap\Core\Exceptions\Objects\EmailAddressInvalid;
8
9
final class EmailAddress
10
{
11
    private string $email;
12
13
    public function __construct(string $email)
14
    {
15
        if (!(filter_var($email, FILTER_VALIDATE_EMAIL))) {
16
            throw new EmailAddressInvalid('The provided email address is not valid');
17
        }
18
        $this->email = $email;
19
    }
20
21
    public function equals(EmailAddress $email): bool
22
    {
23
        return ($this->email === $email->__toString());
24
    }
25
26
    public function __toString(): string
27
    {
28
        return $this->email;
29
    }
30
}
31