Completed
Push — master ( 45f1dd...1bb174 )
by Peter
02:07
created

EmailIdentity::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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