EmailIdentity   A
last analyzed

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 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
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
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