| Total Complexity | 9 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | final class PropertyAccessInjector implements Injector |
||
| 7 | { |
||
| 8 | 22 | public function inject(/*object */$target, string $property, /*object */$object): void |
|
| 11 | } |
||
| 12 | |||
| 13 | 22 | private function createInjector(/*object */$target, string $property): \Closure |
|
| 14 | { |
||
| 15 | $injector = function (/*object */$object) use ($property): void { |
||
| 16 | 21 | if (null === $this->$property) { |
|
| 17 | 20 | $this->$property = $object; |
|
| 18 | } |
||
| 19 | 22 | }; |
|
| 20 | |||
| 21 | 22 | return $injector->bindTo($target, $this->findScope($target, $property)); |
|
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param object $target |
||
| 26 | * |
||
| 27 | * @return object|string |
||
| 28 | */ |
||
| 29 | 22 | private function findScope(/*object */$target, string $property) |
|
| 30 | { |
||
| 31 | 22 | if (\property_exists($target, $property)) { |
|
| 32 | 20 | return $target; |
|
| 33 | } |
||
| 34 | |||
| 35 | 8 | return $this->findParentScope($target, $property); |
|
| 36 | } |
||
| 37 | |||
| 38 | 8 | private function findParentScope(/*object */$target, string $property): string |
|
| 51 | } |
||
| 52 | } |
||
| 53 |