Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| RuntimeException | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| forNonCallableExtension | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forNonPublicMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forInvalidParameterType | |
100.00% |
4 / 4 |
|
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 | /** |
| 22 | * Exception type used to represent runtime errors specific to the container context. |
| 23 | * |
| 24 | * This class MUST be thrown when an error occurs due to invalid runtime behavior |
| 25 | * such as misconfigured extensions or illegal method accessibility. |
| 26 | */ |
| 27 | class RuntimeException extends \RuntimeException |
| 28 | { |
| 29 | /** |
| 30 | * Creates an exception for a non-callable service extension. |
| 31 | * |
| 32 | * This method MUST be used when a value intended to act as a service extension |
| 33 | * is not callable, violating the expected contract of container extensions. |
| 34 | * |
| 35 | * @param string $service the identifier of the service with the invalid extension |
| 36 | * @param string $given the type or class name of the invalid value |
| 37 | * |
| 38 | * @return self a RuntimeException instance with a descriptive message |
| 39 | */ |
| 40 | public static function forNonCallableExtension(string $service, string $given): self |
| 41 | { |
| 42 | return new self(\sprintf('Service "%s" extension MUST be callable, "%s" given.', $service, $given)); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates an exception for attempting to use a non-public method. |
| 47 | * |
| 48 | * This method SHOULD be used when trying to invoke a method that is not declared public, |
| 49 | * thereby violating service visibility requirements. |
| 50 | * |
| 51 | * @param string $class the fully qualified class name |
| 52 | * @param string $method the name of the method that is not publicly accessible |
| 53 | * |
| 54 | * @return self a RuntimeException indicating the method MUST be public |
| 55 | */ |
| 56 | public static function forNonPublicMethod(string $class, string $method): self |
| 57 | { |
| 58 | return new self(\sprintf('Method "%s::%s" MUST be public to be invoked as a service.', $class, $method)); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates an exception for an invalid parameter type. |
| 63 | * |
| 64 | * This method MUST be used when a parameter expected to represent a class name |
| 65 | * or interface name does not satisfy this constraint. |
| 66 | * |
| 67 | * @param string $parameter the name of the parameter with the invalid type |
| 68 | * |
| 69 | * @return self a RuntimeException instance with a descriptive message |
| 70 | */ |
| 71 | public static function forInvalidParameterType(string $parameter): self |
| 72 | { |
| 73 | return new self(\sprintf( |
| 74 | 'Parameter "%s" is not a valid type. It MUST be a class name or an interface name.', |
| 75 | $parameter |
| 76 | )); |
| 77 | } |
| 78 | } |