Passed
Push — master ( 5bb122...61ffee )
by Aleksandr
02:16
created

Attribute::getValueModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 *
5
 * @author    Aleksandr Drobotik <[email protected]>
6
 * @copyright 2023 Aleksandr Drobotik
7
 * @license   https://opensource.org/license/mit  The MIT License
8
 */
9
declare(strict_types=1);
10
11
namespace Drobotik\Eav;
12
13
use Drobotik\Eav\Enum\_ATTR;
14
use Drobotik\Eav\Enum\ATTR_TYPE;
15
use Drobotik\Eav\Exception\AttributeException;
16
use Drobotik\Eav\Interface\StrategyInterface;
17
use Drobotik\Eav\Trait\ContainerTrait;
18
19
class Attribute
20
{
21
    use ContainerTrait;
22
23
    private AttributeBag      $bag;
24
    private AttributeSet      $attributeSet;
0 ignored issues
show
introduced by
The private property $attributeSet is not used, and could be removed.
Loading history...
25
    private StrategyInterface $strategy;
0 ignored issues
show
introduced by
The private property $strategy is not used, and could be removed.
Loading history...
26
27
    public function __construct()
28
    {
29
        $this->setBag(new AttributeBag());
30
    }
31
32 1
    public function getBag(): AttributeBag
33
    {
34 1
        return $this->bag;
35
    }
36
37 1
    public function setBag(AttributeBag $bag): self
38
    {
39 1
        $this->bag = $bag;
40
41 1
        return $this;
42
    }
43
44 1
    public function getKey(): ?int
45
    {
46 1
        return $this->getBag()->getField(_ATTR::ID);
47
    }
48
49 1
    public function setKey(?int $key): self
50
    {
51 1
        $this->getBag()->setField(_ATTR::ID, $key);
52
53 1
        return $this;
54
    }
55
56 1
    public function getDomainKey(): ?int
57
    {
58 1
        return $this->getBag()->getField(_ATTR::DOMAIN_ID);
59
    }
60
61 1
    public function setDomainKey(?int $key): self
62
    {
63 1
        $this->getBag()->setField(_ATTR::DOMAIN_ID, $key);
64
65 1
        return $this;
66
    }
67
68 1
    public function getName(): ?string
69
    {
70 1
        return $this->getBag()->getField(_ATTR::NAME);
71
    }
72
73 1
    public function setName(?string $name): self
74
    {
75 1
        $this->getBag()->setField(_ATTR::NAME, $name);
76
77 1
        return $this;
78
    }
79
80
    /**
81
     * @throws AttributeException
82
     */
83 2
    public function getType(): ATTR_TYPE
84
    {
85 2
        $type = $this->getBag()->getField(_ATTR::TYPE);
86 2
        return ATTR_TYPE::getCase($type);
87
    }
88
89 1
    public function setType(string $type): self
90
    {
91 1
        $this->getBag()->setField(_ATTR::TYPE, $type);
92
93 1
        return $this;
94
    }
95
96 1
    public function getStrategy(): string
97
    {
98 1
        return $this->getBag()->getField(_ATTR::STRATEGY);
99
    }
100
101 1
    public function setStrategy(string $strategy): self
102
    {
103 1
        $this->getBag()->setField(_ATTR::STRATEGY, $strategy);
104
105 1
        return $this;
106
    }
107
108 1
    public function getSource(): ?string
109
    {
110 1
        return $this->getBag()->getField(_ATTR::SOURCE);
111
    }
112
113 1
    public function setSource(?string $source): self
114
    {
115 1
        $this->getBag()->setField(_ATTR::SOURCE, $source);
116
117 1
        return $this;
118
    }
119
120 1
    public function getDefaultValue(): ?string
121
    {
122 1
        return $this->getBag()->getField(_ATTR::DEFAULT_VALUE);
123
    }
124
125 1
    public function setDefaultValue($value): self
126
    {
127 1
        $this->getBag()->setField(_ATTR::DEFAULT_VALUE, $value);
128
129 1
        return $this;
130
    }
131
132 1
    public function getDescription(): string
133
    {
134 1
        return $this->getBag()->getField(_ATTR::DESCRIPTION);
135
    }
136
137 1
    public function setDescription($value): self
138
    {
139 1
        $this->getBag()->setField(_ATTR::DESCRIPTION, $value);
140
141 1
        return $this;
142
    }
143
}
144