Passed
Push — master ( 57eb13...500eb5 )
by Aleksandr
34:06
created

Attribute::setGroupKey()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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 getGroupKey(): ?int
66
    {
67 1
        return (int) $this->getBag()->getField(_ATTR::GROUP_ID);
68
    }
69
70 1
    public function setGroupKey($key): self
71
    {
72 1
        $this->getBag()->setField(_ATTR::GROUP_ID, $key);
73
74 1
        return $this;
75
    }
76
77
    public function getName(): ?string
78
    {
79
        return $this->getBag()->getField(_ATTR::NAME);
80 2
    }
81
82 2
    public function setName(?string $name): self
83 2
    {
84
        $this->getBag()->setField(_ATTR::NAME, $name);
85
86 1
        return $this;
87
    }
88 1
89
    /**
90 1
     * @throws AttributeException
91
     */
92
    public function getType(): string
93 1
    {
94
        $type = $this->getBag()->getField(_ATTR::TYPE);
95 1
        return ATTR_TYPE::getCase($type);
96
    }
97
98 1
    public function setType(string $type): self
99
    {
100 1
        $this->getBag()->setField(_ATTR::TYPE, $type);
101
102 1
        return $this;
103
    }
104
105 1
    public function getStrategy(): string
106
    {
107 1
        return $this->getBag()->getField(_ATTR::STRATEGY);
108
    }
109
110 1
    public function setStrategy(string $strategy): self
111
    {
112 1
        $this->getBag()->setField(_ATTR::STRATEGY, $strategy);
113
114 1
        return $this;
115
    }
116
117 1
    public function getSource(): ?string
118
    {
119 1
        return $this->getBag()->getField(_ATTR::SOURCE);
120
    }
121
122 1
    public function setSource(?string $source): self
123
    {
124 1
        $this->getBag()->setField(_ATTR::SOURCE, $source);
125
126 1
        return $this;
127
    }
128
129 1
    public function getDefaultValue(): ?string
130
    {
131 1
        return $this->getBag()->getField(_ATTR::DEFAULT_VALUE);
132
    }
133
134 1
    public function setDefaultValue($value): self
135
    {
136 1
        $this->getBag()->setField(_ATTR::DEFAULT_VALUE, $value);
137
138 1
        return $this;
139
    }
140
141
    public function getDescription(): string
142
    {
143
        return $this->getBag()->getField(_ATTR::DESCRIPTION);
144
    }
145
146
    public function setDescription($value): self
147
    {
148
        $this->getBag()->setField(_ATTR::DESCRIPTION, $value);
149
150
        return $this;
151
    }
152
}
153