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 | 401 | final public function inputData(InputDataInterface $inputData): static |
|
16 | { |
||
17 | 401 | $new = clone $this; |
|
18 | 401 | $new->inputData = $inputData; |
|
19 | 401 | $new->useCustomName = false; |
|
20 | 401 | $new->useCustomValue = false; |
|
21 | 401 | return $new; |
|
22 | } |
||
23 | |||
24 | 402 | final protected function getInputData(): InputDataInterface |
|
31 | } |
||
32 | |||
33 | 3 | final public function name(?string $name): static |
|
34 | { |
||
35 | 3 | $new = clone $this; |
|
36 | 3 | $new->customName = $name; |
|
37 | 3 | $new->useCustomName = true; |
|
38 | 3 | return $new; |
|
39 | } |
||
40 | |||
41 | 2 | final public function value(mixed $value): static |
|
42 | { |
||
43 | 2 | $new = clone $this; |
|
44 | 2 | $new->customValue = $value; |
|
45 | 2 | $new->useCustomValue = true; |
|
46 | 2 | return $new; |
|
47 | } |
||
48 | |||
49 | 369 | final protected function getName(): ?string |
|
50 | { |
||
51 | 369 | return $this->useCustomName |
|
52 | 2 | ? $this->customName |
|
53 | 369 | : $this->getInputData()->getName(); |
|
54 | } |
||
55 | |||
56 | 366 | final protected function getValue(): mixed |
|
61 | } |
||
62 | } |
||
63 |