Passed
Push — master ( 17e6cc...350d8b )
by Aleksandr
41:29 queued 06:24
created

Entity::getDomainKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 *
5
 * @author    Alex Kuperwood <[email protected]>
6
 * @copyright 2025 Alex Kuperwood
7
 * @license   https://opensource.org/license/mit  The MIT License
8
 */
9
declare(strict_types=1);
10
11
namespace Kuperwood\Eav;
12
13
use Kuperwood\Eav\Result\Result;
14
15
class Entity
16
{
17
    private $key;
18
    private $domainKey;
19
    private AttributeSet $attributeSet;
20
    private EntityBag $bag;
21
    private EntityGnome $manager;
22
23 3
    public function __construct()
24
    {
25 3
        $this->bag = (new EntityBag())->setEntity($this);
26 3
        $this->attributeSet = new AttributeSet();
27 3
        $this->attributeSet->setEntity($this);
28 3
        $this->manager = new EntityGnome($this);
29
    }
30
31 2
    public function getKey(): int
32
    {
33 2
        return $this->key;
34
    }
35
36 2
    public function setKey(int $key): self
37
    {
38 2
        $this->key = $key;
39
40 2
        return $this;
41
    }
42
43 2
    public function hasKey(): bool
44
    {
45 2
        return isset($this->key) && 0 !== $this->key;
46
    }
47
48 2
    public function setDomainKey($key): self
49
    {
50 2
        $this->domainKey = $key;
51
52 2
        return $this;
53
    }
54
55 2
    public function getDomainKey()
56
    {
57 2
        return $this->domainKey;
58
    }
59
60 2
    public function hasDomainKey(): bool
61
    {
62 2
        return isset($this->domainKey) && 0 !== $this->domainKey;
63
    }
64
65 1
    public function getGnome(): EntityGnome
66
    {
67 1
        return $this->manager;
68
    }
69
70 1
    public function getAttributeSet(): ?AttributeSet
71
    {
72 1
        return $this->attributeSet;
73
    }
74
75 1
    public function setAttributeSet(AttributeSet $attributeSet): self
76
    {
77 1
        $attributeSet->setEntity($this);
78 1
        $this->attributeSet = $attributeSet;
79
80 1
        return $this;
81
    }
82
83 1
    public function getBag(): EntityBag
84
    {
85 1
        return $this->bag;
86
    }
87
88 1
    public function find(): Result
89
    {
90 1
        return $this->getGnome()->find();
91
    }
92
93 3
    public function save(): Result
94
    {
95 3
        return $this->getGnome()->save();
96
    }
97
98 3
    public function delete(): Result
99
    {
100 3
        return $this->getGnome()->delete();
101
    }
102
103 1
    public function validate(): Result
104
    {
105 1
        return $this->getGnome()->validate();
106
    }
107
108 1
    public function toArray(): array
109
    {
110 1
        return $this->getGnome()->toArray();
111
    }
112
}
113