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

Attribute::setDomainKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
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\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