Passed
Push — master ( 83edb5...5bb122 )
by Aleksandr
02:51
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\Model\ValueBase;
18
use Drobotik\Eav\Trait\ContainerTrait;
19
20
class Attribute
21
{
22
    use ContainerTrait;
23
24
    private AttributeBag      $bag;
25
    private AttributeSet      $attributeSet;
0 ignored issues
show
introduced by
The private property $attributeSet is not used, and could be removed.
Loading history...
26
    private StrategyInterface $strategy;
0 ignored issues
show
introduced by
The private property $strategy is not used, and could be removed.
Loading history...
27
28
    public function __construct()
29
    {
30
        $this->setBag(new AttributeBag());
31
    }
32
33 1
    public function getBag(): AttributeBag
34
    {
35 1
        return $this->bag;
36
    }
37
38 1
    public function setBag(AttributeBag $bag): self
39
    {
40 1
        $this->bag = $bag;
41
42 1
        return $this;
43
    }
44
45 1
    public function getKey(): ?int
46
    {
47 1
        return $this->getBag()->getField(_ATTR::ID);
48
    }
49
50 1
    public function setKey(?int $key): self
51
    {
52 1
        $this->getBag()->setField(_ATTR::ID, $key);
53
54 1
        return $this;
55
    }
56
57 1
    public function getDomainKey(): ?int
58
    {
59 1
        return $this->getBag()->getField(_ATTR::DOMAIN_ID);
60
    }
61
62 1
    public function setDomainKey(?int $key): self
63
    {
64 1
        $this->getBag()->setField(_ATTR::DOMAIN_ID, $key);
65
66 1
        return $this;
67
    }
68
69 1
    public function getName(): ?string
70
    {
71 1
        return $this->getBag()->getField(_ATTR::NAME);
72
    }
73
74 1
    public function setName(?string $name): self
75
    {
76 1
        $this->getBag()->setField(_ATTR::NAME, $name);
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @throws AttributeException
83
     */
84 2
    public function getType(): ATTR_TYPE
85
    {
86 2
        $type = $this->getBag()->getField(_ATTR::TYPE);
87 2
        return ATTR_TYPE::getCase($type);
88
    }
89
90 1
    public function setType(string $type): self
91
    {
92 1
        $this->getBag()->setField(_ATTR::TYPE, $type);
93
94 1
        return $this;
95
    }
96
97 1
    public function getStrategy(): string
98
    {
99 1
        return $this->getBag()->getField(_ATTR::STRATEGY);
100
    }
101
102 1
    public function setStrategy(string $strategy): self
103
    {
104 1
        $this->getBag()->setField(_ATTR::STRATEGY, $strategy);
105
106 1
        return $this;
107
    }
108
109 1
    public function getSource(): ?string
110
    {
111 1
        return $this->getBag()->getField(_ATTR::SOURCE);
112
    }
113
114 1
    public function setSource(?string $source): self
115
    {
116 1
        $this->getBag()->setField(_ATTR::SOURCE, $source);
117
118 1
        return $this;
119
    }
120
121 1
    public function getDefaultValue(): ?string
122
    {
123 1
        return $this->getBag()->getField(_ATTR::DEFAULT_VALUE);
124
    }
125
126 1
    public function setDefaultValue($value): self
127
    {
128 1
        $this->getBag()->setField(_ATTR::DEFAULT_VALUE, $value);
129
130 1
        return $this;
131
    }
132
133 1
    public function getDescription(): string
134
    {
135 1
        return $this->getBag()->getField(_ATTR::DESCRIPTION);
136
    }
137
138 1
    public function setDescription($value): self
139
    {
140 1
        $this->getBag()->setField(_ATTR::DESCRIPTION, $value);
141
142 1
        return $this;
143
    }
144
145
    public function getValueModel(): ValueBase
146
    {
147
        return $this->getType()->model();
148
    }
149
}
150