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

PropertyAccessInjector::createInjector()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 1
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
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