Lines 92.85% 13 / 14
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 getEntity 100.00% 1 / 1 100.00% 1 / 1 1
 setter 100.00% 5 / 5 100.00% 1 / 1 1
 setValueAtPath 85.71% 6 / 7 0.00% 0 / 1 3.03
7class 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(mixed ...$propertyPath): callable
22    {
23        $entity = $this->getEntity();
24
25        return function (mixed $newValue) use ($propertyPath, $entity): Entity {
26            self::setValueAtPath($entity, $propertyPath, $newValue);
27
28            return $entity;
29        };
30    }
31
32    private static function setValueAtPath(mixed &$container, array $propertyPath, mixed $newValue): void
33    {
34        $property = array_shift($propertyPath);
35        if ($property === null) {
36            return;
37        }
38        if ($propertyPath === []) {
39            $container[$property] = $newValue;
40
41            return;
42        }
43
44        self::setValueAtPath($container[$property], $propertyPath, $newValue);
45    }
46}