Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| RuntimeException | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forUnsupportedType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forMethodWithoutParameters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forMethodParameterWithoutType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forListenerWithoutParameters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forListenerParameterWithoutType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forCacheInvalidationFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forWebhookRequestFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/event-dispatcher. |
| 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/event-dispatcher |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\EventDispatcher\Exception; |
| 20 | |
| 21 | use Throwable; |
| 22 | |
| 23 | /** |
| 24 | * Represent runtime failures raised by the event dispatcher package. |
| 25 | */ |
| 26 | class RuntimeException extends \RuntimeException |
| 27 | { |
| 28 | /** |
| 29 | * Prevent direct instantiation outside the named factories. |
| 30 | * |
| 31 | * @param string $message exception message |
| 32 | * @param int $code exception code |
| 33 | * @param Throwable|null $previous previous exception |
| 34 | */ |
| 35 | private function __construct(string $message = '', int $code = 0, ?Throwable $previous = null) |
| 36 | { |
| 37 | parent::__construct($message, $code, $previous); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Create an exception for an unsupported listener value. |
| 42 | * |
| 43 | * @param mixed $listener listener value that could not be resolved |
| 44 | * |
| 45 | * @return self exception describing the unsupported listener type |
| 46 | */ |
| 47 | public static function forUnsupportedType(mixed $listener): self |
| 48 | { |
| 49 | return new self(\sprintf('Unsupported listener type: "%s".', get_debug_type($listener))); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Create an exception for a reflected method without parameters. |
| 54 | * |
| 55 | * @return self exception describing the invalid reflected method |
| 56 | */ |
| 57 | public static function forMethodWithoutParameters(): self |
| 58 | { |
| 59 | return new self('Method has no parameters'); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Create an exception for a reflected method whose first parameter has no type. |
| 64 | * |
| 65 | * @return self exception describing the missing method parameter type |
| 66 | */ |
| 67 | public static function forMethodParameterWithoutType(): self |
| 68 | { |
| 69 | return new self('Parameter has no type'); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Create an exception for a listener callable without parameters. |
| 74 | * |
| 75 | * @return self exception describing the invalid listener signature |
| 76 | */ |
| 77 | public static function forListenerWithoutParameters(): self |
| 78 | { |
| 79 | return new self('Listener has no parameters'); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Create an exception for a listener callable whose first parameter has no type. |
| 84 | * |
| 85 | * @return self exception describing the missing listener parameter type |
| 86 | */ |
| 87 | public static function forListenerParameterWithoutType(): self |
| 88 | { |
| 89 | return new self('Listener parameter has no type'); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Create an exception for a cache invalidation failure. |
| 94 | * |
| 95 | * @param list<string> $keys cache keys that could not be invalidated |
| 96 | * |
| 97 | * @return self exception describing the cache invalidation failure |
| 98 | */ |
| 99 | public static function forCacheInvalidationFailure(array $keys): self |
| 100 | { |
| 101 | return new self(\sprintf('Failed to invalidate cache keys: "%s".', implode('", "', $keys))); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Create an exception for an unsuccessful webhook response. |
| 106 | * |
| 107 | * @param string $uri webhook URI that returned an unsuccessful response |
| 108 | * @param int $statusCode HTTP status code returned by the webhook endpoint |
| 109 | * |
| 110 | * @return self exception describing the webhook publishing failure |
| 111 | */ |
| 112 | public static function forWebhookRequestFailure(string $uri, int $statusCode): self |
| 113 | { |
| 114 | return new self(\sprintf('Webhook request to "%s" failed with status code %d.', $uri, $statusCode)); |
| 115 | } |
| 116 | } |