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

Entity   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 96
ccs 39
cts 39
cp 1
rs 10
c 1
b 0
f 0
wmc 18

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getBag() 0 3 1
A getAttributeSet() 0 3 1
A setAttributeSet() 0 6 1
A find() 0 3 1
A hasKey() 0 3 2
A getGnome() 0 3 1
A __construct() 0 6 1
A delete() 0 3 1
A hasDomainKey() 0 3 2
A getDomainKey() 0 3 1
A toArray() 0 3 1
A validate() 0 3 1
A setDomainKey() 0 5 1
A save() 0 3 1
A getKey() 0 3 1
A setKey() 0 5 1
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