Total Complexity | 4 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | final class ErrorContext extends AbstractContext |
||
14 | { |
||
15 | /** @psalm-suppress InvalidClassConstantType */ |
||
16 | public const TYPE = 'bear_resource_error'; |
||
17 | |||
18 | /** @psalm-suppress InvalidClassConstantType */ |
||
19 | public const SCHEMA_URL = 'https://bearsunday.github.io/BEAR.Resource/schemas/error-context.json'; |
||
20 | |||
21 | public readonly string $exceptionId; |
||
22 | public readonly string $exceptionAsString; |
||
23 | |||
24 | public function __construct( |
||
25 | Throwable $exception, |
||
26 | string $exceptionId = '', |
||
27 | ?OpenContext $openContext = null, |
||
28 | ) { |
||
29 | $this->exceptionAsString = (string) $exception; |
||
|
|||
30 | $this->exceptionId = $exceptionId !== '' ? $exceptionId : $this->createExceptionId(); |
||
31 | |||
32 | // OpenContext is intentionally unused in Compact profile (no profiling) |
||
33 | unset($openContext); |
||
34 | } |
||
35 | |||
36 | public static function create( |
||
37 | Throwable $exception, |
||
38 | string $exceptionId = '', |
||
39 | ?OpenContext $openContext = null, |
||
40 | ): self { |
||
41 | return new self($exception, $exceptionId, $openContext); |
||
42 | } |
||
43 | |||
44 | private function createExceptionId(): string |
||
50 | } |
||
51 | } |
||
52 |