Total Complexity | 9 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait InputDataWithCustomNameAndValueTrait |
||
8 | { |
||
9 | private ?InputDataInterface $inputData = null; |
||
10 | private bool $useCustomName = false; |
||
11 | private ?string $customName = null; |
||
12 | private bool $useCustomValue = false; |
||
13 | private mixed $customValue = null; |
||
14 | |||
15 | 246 | final public function inputData(InputDataInterface $inputData): static |
|
16 | { |
||
17 | 246 | $new = clone $this; |
|
18 | 246 | $new->inputData = $inputData; |
|
19 | 246 | $new->useCustomName = false; |
|
20 | 246 | $new->useCustomValue = false; |
|
21 | 246 | return $new; |
|
22 | } |
||
23 | |||
24 | 484 | final protected function getInputData(): InputDataInterface |
|
31 | } |
||
32 | |||
33 | 223 | final public function name(?string $name): static |
|
34 | { |
||
35 | 223 | $new = clone $this; |
|
36 | 223 | $new->customName = $name; |
|
37 | 223 | $new->useCustomName = true; |
|
38 | 223 | return $new; |
|
39 | } |
||
40 | |||
41 | 40 | final public function value(mixed $value): static |
|
42 | { |
||
43 | 40 | $new = clone $this; |
|
44 | 40 | $new->customValue = $value; |
|
45 | 40 | $new->useCustomValue = true; |
|
46 | 40 | return $new; |
|
47 | } |
||
48 | |||
49 | 481 | final protected function getName(): ?string |
|
50 | { |
||
51 | 481 | return $this->useCustomName |
|
52 | 221 | ? $this->customName |
|
53 | 481 | : $this->getInputData()->getName(); |
|
54 | } |
||
55 | |||
56 | 468 | final protected function getValue(): mixed |
|
61 | } |
||
62 | } |
||
63 |