Email   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 76
ccs 18
cts 18
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getEmail() 0 4 1
A getUsername() 0 4 1
A getHostname() 0 4 1
A getMx() 0 6 1
A mxIsValid() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace WSW\Email;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class Email
9
 *
10
 * @package WSW\Email
11
 * @author Ronaldo Matos Rodrigues <[email protected]>
12
 */
13
final class Email
14
{
15
    use Validator;
16
17
    /**
18
     * @var string
19
     */
20
    private $username;
21
22
    /**
23
     * @var string
24
     */
25
    private $hostname;
26
27
    /**
28
     * @param string $email
29
     */
30 9
    public function __construct($email)
31
    {
32 9
        if (!$this->emailIsValid($email)) {
33 1
            throw new InvalidArgumentException('You should inform a valid email.');
34
        }
35
36 8
        list($this->username, $this->hostname) = explode('@', $email);
37 8
    }
38
39
    /**
40
     * @return string
41
     */
42 2
    public function getEmail()
43
    {
44 2
        return sprintf('%s@%s', $this->username, $this->hostname);
45
    }
46
47
    /**
48
     * @return string
49
     */
50 1
    public function getUsername()
51
    {
52 1
        return $this->username;
53
    }
54
55
    /**
56
     * @return string
57
     */
58 4
    public function getHostname()
59
    {
60 4
        return $this->hostname;
61
    }
62
63
    /**
64
     * @return array
65
     */
66 1
    public function getMx()
67
    {
68 1
        getmxrr($this->getHostname(), $arr);
69
70 1
        return $arr;
71
    }
72
73
    /**
74
     * @return bool
75
     */
76 2
    public function mxIsValid()
77
    {
78 2
        return $this->checkMxIsValid($this->getHostname());
79
    }
80
81
    /**
82
     * @return string
83
     */
84 1
    public function __toString()
85
    {
86 1
        return $this->getEmail();
87
    }
88
}
89