HasIdentity::compareDomainId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Nord\Lumen\Core\Traits;
4
5
use Nord\Lumen\Core\Domain\DomainId;
6
use Nord\Lumen\Core\Exceptions\ImmutableProperty;
7
8
trait HasIdentity
9
{
10
    /**
11
     * @var DomainId
12
     */
13
    private $domainId;
14
15
    /**
16
     * @param DomainId $domainId
17
     *
18
     * @return bool
19
     */
20
    public function compareDomainId(DomainId $domainId)
21
    {
22
        return $this->domainId->getValue() === $domainId->getValue();
23
    }
24
25
    /**
26
     * @return DomainId
27
     */
28
    public function getDomainId()
29
    {
30
        return $this->domainId;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getDomainIdValue()
37
    {
38
        return $this->getDomainId()->getValue();
39
    }
40
41
    /**
42
     * @param null|string $value
43
     *
44
     * @throws \Exception
45
     */
46
    private function createDomainId($value = null)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
47
    {
48
        $this->setDomainId(new DomainId($value));
49
    }
50
51
    /**
52
     * @param DomainId $domainId
53
     *
54
     * @throws ImmutableProperty
55
     */
56
    private function setDomainId(DomainId $domainId)
57
    {
58
        if ($this->domainId !== null) {
59
            throw new ImmutableProperty('Domain ID cannot be changed.');
60
        }
61
62
        $this->domainId = $domainId;
63
    }
64
}
65