EmailIdentity::getDomain()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace PeterNijssen\Ses\Model;
4
5
use PeterNijssen\Ses\Exception\InvalidIdentityException;
6
7
/**
8
 * Email identity
9
 */
10
class EmailIdentity extends SesIdentity implements IdentityInterface
11
{
12
    /**
13
     * Domain identity constructor.
14
     *
15
     * @param string $identity domain
16
     *
17
     * @throws InvalidIdentityException
18
     */
19 11
    public function __construct($identity)
20
    {
21 11
        if (!preg_match('/^.+\@\S+\.\S+$/', $identity)) {
22 1
            throw new InvalidIdentityException("The identity is not a valid email address");
23
        }
24
25 11
        $this->identity = $identity;
26 11
    }
27
28
    /**
29
     * Get the domain for this identity
30
     *
31
     * @return string
32
     */
33 3
    public function getDomain()
34
    {
35 3
        if (preg_match("/@([^\s]+)/iu", $this->identity, $info)) {
36 3
            return $info[1];
37
        }
38
    }
39
}
40