Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AutowiringException | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| forUnresolvableParameter | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/container. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2025-2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/container |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Container\Exception; |
| 20 | |
| 21 | use RuntimeException; |
| 22 | use Throwable; |
| 23 | use Psr\Container\ContainerExceptionInterface; |
| 24 | |
| 25 | /** |
| 26 | * Signals a constructor dependency graph that cannot be inferred. |
| 27 | * |
| 28 | * Optional arguments MAY use their defaults for this structural failure. |
| 29 | * Execution failures and cycles MUST use ContainerException instead. |
| 30 | */ |
| 31 | class AutowiringException extends RuntimeException implements ContainerExceptionInterface |
| 32 | { |
| 33 | /** |
| 34 | * Creates an exception for a constructor parameter without an inferable value. |
| 35 | * |
| 36 | * @param string $class the class that declares the constructor |
| 37 | * @param string $parameter the parameter name |
| 38 | * @param string|null $type the declared type, or null for an untyped parameter |
| 39 | * @param Throwable|null $previous the structural dependency resolution failure |
| 40 | * |
| 41 | * @return self an exception identifying the parameter and preserving its cause |
| 42 | */ |
| 43 | public static function forUnresolvableParameter( |
| 44 | string $class, |
| 45 | string $parameter, |
| 46 | ?string $type, |
| 47 | ?Throwable $previous = null |
| 48 | ): self { |
| 49 | return new self(\sprintf( |
| 50 | 'Cannot autowire %s::__construct(): parameter $%s (%s) requires an explicit service or factory.', |
| 51 | $class, |
| 52 | $parameter, |
| 53 | $type ?? 'untyped', |
| 54 | ), 0, $previous); |
| 55 | } |
| 56 | } |