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

AttributeContainer::getValueValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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\Value\ValueAction;
14
use Kuperwood\Eav\Value\ValueManager;
15
use Kuperwood\Eav\Value\ValueValidator;
16
use Exception;
17
18
class AttributeContainer
19
{
20
    protected Attribute $attribute;
21
    protected Strategy $strategy;
22
    protected AttributeSet $attributeSet;
23
    protected AttributeSetAction $attributeSetAction;
24
    protected ValueManager $valueManager;
25
    protected ValueValidator $valueValidator;
26
    protected ValueAction $valueAction;
27
    private array $supported = [
28
        AttributeSet::class,
29
        AttributeSetAction::class,
30
        Attribute::class,
31
        Strategy::class,
32
        ValueManager::class,
33
        ValueValidator::class,
34
        ValueAction::class,
35
    ];
36
37 15
    public function make(string $className)
38
    {
39 15
        if (!in_array($className, $this->supported)) {
40 1
            throw new Exception('not supported');
41
        }
42 14
        $instance = new $className();
43 14
        $instance->setAttributeContainer($this);
44
45 14
        return $instance;
46
    }
47
48 1
    public function makeAttributeSet(): self
49
    {
50 1
        $this->setAttributeSet($this->make(AttributeSet::class));
51
52 1
        return $this;
53
    }
54
55 1
    public function makeAttributeSetAction(): self
56
    {
57 1
        $this->setAttributeSetAction($this->make(AttributeSetAction::class));
58
59 1
        return $this;
60
    }
61
62 1
    public function makeAttribute(): self
63
    {
64 1
        $this->setAttribute($this->make(Attribute::class));
65
66 1
        return $this;
67
    }
68
69 1
    public function makeStrategy(): self
70
    {
71 1
        $this->setStrategy($this->make(Strategy::class));
72
73 1
        return $this;
74
    }
75
76 1
    public function makeValueManager(): self
77
    {
78 1
        $this->setValueManager($this->make(ValueManager::class));
79
80 1
        return $this;
81
    }
82
83 1
    public function makeValueValidator(): self
84
    {
85 1
        $this->setValueValidator($this->make(ValueValidator::class));
86
87 1
        return $this;
88
    }
89
90 1
    public function makeValueAction(): self
91
    {
92 1
        $this->setValueAction($this->make(ValueAction::class));
93
94 1
        return $this;
95
    }
96
97 1
    public function setAttribute(Attribute $attribute): self
98
    {
99 1
        $attribute->setAttributeContainer($this);
100 1
        $this->attribute = $attribute;
101
102 1
        return $this;
103
    }
104
105 1
    public function getAttribute(): Attribute
106
    {
107 1
        return $this->attribute;
108
    }
109
110 1
    public function setValueManager(ValueManager $valueManager): self
111
    {
112 1
        $valueManager->setAttributeContainer($this);
113 1
        $this->valueManager = $valueManager;
114
115 1
        return $this;
116
    }
117
118 1
    public function getValueManager(): ValueManager
119
    {
120 1
        return $this->valueManager;
121
    }
122
123 1
    public function setValueValidator(ValueValidator $valueValidator): self
124
    {
125 1
        $valueValidator->setAttributeContainer($this);
126 1
        $this->valueValidator = $valueValidator;
127
128 1
        return $this;
129
    }
130
131 1
    public function getValueValidator(): ValueValidator
132
    {
133 1
        return $this->valueValidator;
134
    }
135
136 1
    public function setValueAction(ValueAction $valueAction): self
137
    {
138 1
        $valueAction->setAttributeContainer($this);
139 1
        $this->valueAction = $valueAction;
140
141 1
        return $this;
142
    }
143
144 1
    public function getValueAction(): ValueAction
145
    {
146 1
        return $this->valueAction;
147
    }
148
149 1
    public function setStrategy(Strategy $strategy): self
150
    {
151 1
        $strategy->setAttributeContainer($this);
152 1
        $this->strategy = $strategy;
153
154 1
        return $this;
155
    }
156
157 1
    public function getStrategy(): Strategy
158
    {
159 1
        return $this->strategy;
160
    }
161
162 1
    public function setAttributeSet(AttributeSet $attrSet): self
163
    {
164 1
        $attrSet->setAttributeContainer($this);
165 1
        $this->attributeSet = $attrSet;
166
167 1
        return $this;
168
    }
169
170 1
    public function getAttributeSet(): AttributeSet
171
    {
172 1
        return $this->attributeSet;
173
    }
174
175 1
    public function setAttributeSetAction(AttributeSetAction $attrSetAction): self
176
    {
177 1
        $attrSetAction->setAttributeContainer($this);
178 1
        $this->attributeSetAction = $attrSetAction;
179
180 1
        return $this;
181
    }
182
183 1
    public function getAttributeSetAction(): AttributeSetAction
184
    {
185 1
        return $this->attributeSetAction;
186
    }
187
}
188