EmailAddress   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 44
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getLocalPart() 0 7 1
A getDomainPart() 0 7 1
1
<?php
2
3
namespace ValueObjects\Web;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class EmailAddress extends StringLiteral
9
{
10
    /**
11
     * Returns an EmailAddress object given a PHP native string as parameter.
12
     *
13
     * @param string $value
14
     */
15 4
    public function __construct($value)
16
    {
17 4
        $filteredValue = filter_var($value, FILTER_VALIDATE_EMAIL);
18
19 4
        if ($filteredValue === false) {
20 1
            throw new InvalidNativeArgumentException($value, array('string (valid email address)'));
21
        }
22
23 3
        $this->value = $filteredValue;
24 3
    }
25
26
    /**
27
     * Returns the local part of the email address
28
     *
29
     * @return StringLiteral
30
     */
31 1
    public function getLocalPart()
32
    {
33 1
        $parts = explode('@', $this->toNative());
34 1
        $localPart = new StringLiteral($parts[0]);
35
36 1
        return $localPart;
37
    }
38
39
    /**
40
     * Returns the domain part of the email address
41
     *
42
     * @return Domain
43
     */
44 1
    public function getDomainPart()
45
    {
46 1
        $parts = \explode('@', $this->toNative());
47 1
        $domain = \trim($parts[1], '[]');
48
49 1
        return Domain::specifyType($domain);
50
    }
51
}
52