Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
8 / 8 |
|
83.33% |
5 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ConstructorResolver | |
100.00% |
7 / 7 |
|
100.00% |
8 / 8 |
|
83.33% |
5 / 6 |
|
100.00% |
3 / 3 |
5.12 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolve | |
100.00% |
5 / 5 |
|
100.00% |
6 / 6 |
|
75.00% |
3 / 4 |
|
100.00% |
1 / 1 |
3.14 | |||
| creator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Wire; |
| 6 | |
| 7 | use Override; |
| 8 | use ReflectionClass; |
| 9 | |
| 10 | /** @psalm-api */ |
| 11 | class ConstructorResolver |
| 12 | { |
| 13 | use ResolvesAbstractFunctions; |
| 14 | |
| 15 | public function __construct( |
| 16 | protected readonly CreatorInterface $creator, |
| 17 | ) {} |
| 18 | |
| 19 | /** @param ReflectionClass|class-string $class */ |
| 20 | public function resolve( |
| 21 | ReflectionClass|string $class, |
| 22 | array $predefinedArgs = [], |
| 23 | array $predefinedTypes = [], |
| 24 | ?callable $injectCallback = null, |
| 25 | ): array { |
| 26 | $rcls = is_string($class) ? new ReflectionClass($class) : $class; |
| 27 | $constructor = $rcls->getConstructor(); |
| 28 | |
| 29 | if ($constructor) { |
| 30 | return $this->resolveArgs($constructor, $predefinedArgs, $predefinedTypes, $injectCallback); |
| 31 | } |
| 32 | |
| 33 | return $predefinedArgs; |
| 34 | } |
| 35 | |
| 36 | #[Override] |
| 37 | public function creator(): CreatorInterface |
| 38 | { |
| 39 | return $this->creator; |
| 40 | } |
| 41 | } |