EmailAddress::getDomainPart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 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