DomainIdentity::getDomain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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