Lines
100.00%
4 / 4
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromException | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromThrowable | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | ||
| toArray | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 12 | final readonly class ExceptionDetails | |
| 13 | { | |
| 14 | public const string CONTEXT_KEY = 'stewartExceptionDetails'; | |
| 15 | ||
| 16 | /** @param ExceptionContext|null $context */ | |
| 17 | public function __construct( | |
| 18 | public string $class, | |
| 19 | public string $reason, | |
| 20 | public ?array $context, | |
| 21 | ) {} | |
| 22 | ||
| 23 | /** @param StewartException<ExceptionReason> $error */ | |
| 24 | public static function fromException(StewartException $error): self | |
| 25 | { | |
| 26 | return new self($error::class, (string) $error->reason->value, $error->context); | |
| 27 | } | |
| 28 | ||
| 29 | public static function fromThrowable(Throwable $error): ?self | |
| 30 | { | |
| 31 | return $error instanceof StewartException ? self::fromException($error) : null; | |
| 32 | } | |
| 33 | ||
| 34 | /** @return array{class: string, reason: string, context: ExceptionContext|null} */ | |
| 35 | public function toArray(): array | |
| 36 | { | |
| 37 | return ['class' => $this->class, 'reason' => $this->reason, 'context' => $this->context]; | |
| 38 | } | |
| 39 | } |