| Total Complexity | 5 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class Handler |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @param callable(): T $callback |
||
| 17 | * |
||
| 18 | * @return T |
||
| 19 | * |
||
| 20 | * @throws \Exception |
||
| 21 | * |
||
| 22 | * @template T |
||
| 23 | */ |
||
| 24 | 41 | public static function withErrorHandlerForXMLReader(callable $callback): mixed |
|
| 25 | { |
||
| 26 | 41 | return self::withErrorHandler(static function (int $code, string $message): bool { |
|
| 27 | 3 | if (str_contains($message, 'XMLReader::')) { |
|
| 28 | 3 | throw new Exception($message, $code); |
|
| 29 | } |
||
| 30 | |||
| 31 | // @codeCoverageIgnoreStart |
||
| 32 | return false; |
||
| 33 | // @codeCoverageIgnoreEnd |
||
| 34 | 41 | }, $callback); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param callable(): T $callback |
||
| 39 | * |
||
| 40 | * @return T |
||
| 41 | * |
||
| 42 | * @throws \DOMException |
||
| 43 | * |
||
| 44 | * @template T |
||
| 45 | */ |
||
| 46 | 62 | public static function withErrorHandlerForDOMDocument(callable $callback): mixed |
|
| 47 | { |
||
| 48 | 62 | return self::withErrorHandler(static function (int $code, string $message): bool { |
|
| 49 | 6 | if (str_contains($message, 'DOMDocument::')) { |
|
| 50 | 6 | throw new DOMException($message, $code); |
|
| 51 | } |
||
| 52 | |||
| 53 | // @codeCoverageIgnoreStart |
||
| 54 | return false; |
||
| 55 | // @codeCoverageIgnoreEnd |
||
| 56 | 62 | }, $callback); |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Register custom error handler to throw \Exception on warning message |
||
| 61 | */ |
||
| 62 | 74 | private static function withErrorHandler(callable $errorCallback, callable $functionCallback): mixed |
|
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 |