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

EmailIdentity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 30
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getDomain() 0 6 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