Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Delegate | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getEntity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setter | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities\Helper; |
4 | |
5 | use BO\Zmsentities\Schema\Entity; |
6 | |
7 | class Delegate |
8 | { |
9 | protected $entity; |
10 | |
11 | public function __construct(Entity $entity) |
12 | { |
13 | $this->entity = $entity; |
14 | } |
15 | |
16 | public function getEntity(): Entity |
17 | { |
18 | return $this->entity; |
19 | } |
20 | |
21 | public function setter(...$propertyPath): callable |
22 | { |
23 | $entity = $this->getEntity(); |
24 | return function ($newValue) use ($propertyPath, $entity): Entity { |
25 | $reference = $entity; |
26 | foreach ($propertyPath as $property) { |
27 | $reference =& $reference[$property]; |
28 | } |
29 | $reference = $newValue; |
30 | return $entity; |
31 | }; |
32 | } |
33 | } |