Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
10 / 10 |
|
75.00% |
6 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ConstructorResolver | |
100.00% |
11 / 11 |
|
100.00% |
10 / 10 |
|
75.00% |
6 / 8 |
|
100.00% |
3 / 3 |
6.56 | |
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% |
9 / 9 |
|
100.00% |
8 / 8 |
|
66.67% |
4 / 6 |
|
100.00% |
1 / 1 |
4.59 | |||
| 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 Celema\Wire; |
| 6 | |
| 7 | use Celema\Wire\Exception\WireException; |
| 8 | use Override; |
| 9 | use ReflectionClass; |
| 10 | |
| 11 | /** @psalm-api */ |
| 12 | class ConstructorResolver |
| 13 | { |
| 14 | use ResolvesAbstractFunctions; |
| 15 | |
| 16 | public function __construct( |
| 17 | protected readonly CreatorInterface $creator, |
| 18 | ) {} |
| 19 | |
| 20 | /** @param ReflectionClass|class-string $class */ |
| 21 | public function resolve( |
| 22 | ReflectionClass|string $class, |
| 23 | array $predefinedArgs = [], |
| 24 | array $predefinedTypes = [], |
| 25 | ?callable $injectCallback = null, |
| 26 | ): array { |
| 27 | $rcls = is_string($class) ? new ReflectionClass($class) : $class; |
| 28 | $constructor = $rcls->getConstructor(); |
| 29 | |
| 30 | if ($constructor) { |
| 31 | return $this->resolveArgs($constructor, $predefinedArgs, $predefinedTypes, $injectCallback); |
| 32 | } |
| 33 | |
| 34 | // Arguments for a class without a constructor would be dropped silently. |
| 35 | if ($predefinedArgs !== []) { |
| 36 | throw new WireException( |
| 37 | 'Unresolvable: ' . $rcls->getName() . ' has no constructor, but arguments were given', |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | return []; |
| 42 | } |
| 43 | |
| 44 | #[Override] |
| 45 | public function creator(): CreatorInterface |
| 46 | { |
| 47 | return $this->creator; |
| 48 | } |
| 49 | } |