Email   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A email() 0 4 1
A localPart() 0 4 1
A domain() 0 4 1
A equals() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace LIN3S\SharedKernel\Domain\Model\Email;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class Email
20
{
21
    private $email;
22
    private $domain;
23
    private $localPart;
24
25
    public function __construct($anEmail)
26
    {
27
        if (!filter_var($anEmail, FILTER_VALIDATE_EMAIL)) {
28
            throw new EmailInvalidException();
29
        }
30
        $this->email = $anEmail;
31
        $this->localPart = implode(explode('@', $this->email, -1), '@');
32
        $this->domain = str_replace($this->localPart . '@', '', $this->email);
33
    }
34
35
    public function email()
36
    {
37
        return $this->email;
38
    }
39
40
    public function localPart()
41
    {
42
        return $this->localPart;
43
    }
44
45
    public function domain()
46
    {
47
        return $this->domain;
48
    }
49
50
    public function equals(self $anEmail)
51
    {
52
        return mb_strtolower((string) $this) === mb_strtolower((string) $anEmail);
53
    }
54
55
    public function __toString()
56
    {
57
        return (string) $this->email;
58
    }
59
}
60