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

Attribute   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 32
dl 0
loc 121
ccs 48
cts 48
cp 1
rs 10
c 1
b 0
f 1
wmc 19

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 3 1
A __construct() 0 3 1
A setDomainKey() 0 5 1
A setBag() 0 5 1
A getDefaultValue() 0 3 1
A getSource() 0 3 1
A getBag() 0 3 1
A getDomainKey() 0 3 1
A setSource() 0 5 1
A getType() 0 4 1
A setType() 0 5 1
A setDefaultValue() 0 5 1
A getStrategy() 0 3 1
A getName() 0 3 1
A getDescription() 0 3 1
A setName() 0 5 1
A setKey() 0 5 1
A setDescription() 0 5 1
A setStrategy() 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\Enum\_ATTR;
14
use Kuperwood\Eav\Enum\ATTR_TYPE;
15
use Kuperwood\Eav\Exception\AttributeException;
16
use Kuperwood\Eav\Traits\ContainerTrait;
17
18
class Attribute
19
{
20
    use ContainerTrait;
21
22
    private AttributeBag      $bag;
23
24 1
    public function __construct()
25
    {
26 1
        $this->setBag(new AttributeBag());
27
    }
28
29 1
    public function getBag(): AttributeBag
30
    {
31 1
        return $this->bag;
32
    }
33
34 1
    public function setBag(AttributeBag $bag): self
35
    {
36 1
        $this->bag = $bag;
37
38 1
        return $this;
39
    }
40
41 1
    public function getKey()
42
    {
43 1
        return $this->getBag()->getField(_ATTR::ID);
44
    }
45
46 1
    public function setKey($key): self
47
    {
48 1
        $this->getBag()->setField(_ATTR::ID, $key);
49
50 1
        return $this;
51
    }
52
53 1
    public function getDomainKey(): ?int
54
    {
55 1
        return $this->getBag()->getField(_ATTR::DOMAIN_ID);
56
    }
57
58 1
    public function setDomainKey(?int $key): self
59
    {
60 1
        $this->getBag()->setField(_ATTR::DOMAIN_ID, $key);
61
62 1
        return $this;
63
    }
64
65 1
    public function getName(): ?string
66
    {
67 1
        return $this->getBag()->getField(_ATTR::NAME);
68
    }
69
70 1
    public function setName(?string $name): self
71
    {
72 1
        $this->getBag()->setField(_ATTR::NAME, $name);
73
74 1
        return $this;
75
    }
76
77
    /**
78
     * @throws AttributeException
79
     */
80 2
    public function getType(): string
81
    {
82 2
        $type = $this->getBag()->getField(_ATTR::TYPE);
83 2
        return ATTR_TYPE::getCase($type);
84
    }
85
86 1
    public function setType(string $type): self
87
    {
88 1
        $this->getBag()->setField(_ATTR::TYPE, $type);
89
90 1
        return $this;
91
    }
92
93 1
    public function getStrategy(): string
94
    {
95 1
        return $this->getBag()->getField(_ATTR::STRATEGY);
96
    }
97
98 1
    public function setStrategy(string $strategy): self
99
    {
100 1
        $this->getBag()->setField(_ATTR::STRATEGY, $strategy);
101
102 1
        return $this;
103
    }
104
105 1
    public function getSource(): ?string
106
    {
107 1
        return $this->getBag()->getField(_ATTR::SOURCE);
108
    }
109
110 1
    public function setSource(?string $source): self
111
    {
112 1
        $this->getBag()->setField(_ATTR::SOURCE, $source);
113
114 1
        return $this;
115
    }
116
117 1
    public function getDefaultValue(): ?string
118
    {
119 1
        return $this->getBag()->getField(_ATTR::DEFAULT_VALUE);
120
    }
121
122 1
    public function setDefaultValue($value): self
123
    {
124 1
        $this->getBag()->setField(_ATTR::DEFAULT_VALUE, $value);
125
126 1
        return $this;
127
    }
128
129 1
    public function getDescription(): string
130
    {
131 1
        return $this->getBag()->getField(_ATTR::DESCRIPTION);
132
    }
133
134 1
    public function setDescription($value): self
135
    {
136 1
        $this->getBag()->setField(_ATTR::DESCRIPTION, $value);
137
138 1
        return $this;
139
    }
140
}
141