EmailAddress::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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