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

PropertyAccessInjector::inject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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