DomainIdentity::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2
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