Completed
Pull Request — master (#2)
by Jakub
03:45
created

PropertyAccessInjector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInjector() 0 9 3
A inject() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Zalas\PHPUnit\Doubles\Injector;
5
6
final class PropertyAccessInjector implements Injector
7
{
8 18
    public function inject(/*object */$target, string $property, /*object */$object): void
9
    {
10 18
        $this->createInjector($target)($property, $object);
11
    }
12
13 18
    private function createInjector(/*object */$target): \Closure
14
    {
15
        $injector = function (string $property, /*object */$object): void {
16 18
            if (\property_exists($this, $property) && null === $this->$property) {
17 16
                $this->$property = $object;
18
            }
19 18
        };
20
21 18
        return $injector->bindTo($target, \get_class($target));
22
    }
23
}
24