Completed
Push — master ( bb98fa...b1dd66 )
by Beñat
08:36
created

Email   A

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-2017 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
namespace LIN3S\SharedKernel\Domain\Model\Email;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
class Email
18
{
19
    private $email;
20
    private $domain;
21
    private $localPart;
22
23
    public function __construct($anEmail)
24
    {
25
        if (!filter_var($anEmail, FILTER_VALIDATE_EMAIL)) {
26
            throw new EmailInvalidException();
27
        }
28
        $this->email = $anEmail;
29
        $this->localPart = implode(explode('@', $this->email, -1), '@');
30
        $this->domain = str_replace($this->localPart . '@', '', $this->email);
31
    }
32
33
    public function email()
34
    {
35
        return $this->email;
36
    }
37
38
    public function localPart()
39
    {
40
        return $this->localPart;
41
    }
42
43
    public function domain()
44
    {
45
        return $this->domain;
46
    }
47
48
    public function equals(Email $anEmail)
49
    {
50
        return strtolower((string) $this) === strtolower((string) $anEmail);
51
    }
52
53
    public function __toString()
54
    {
55
        return (string) $this->email;
56
    }
57
}
58