Passed
Pull Request — 1.x (#334)
by Akihito
02:25
created

ResourceErrorContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 8
c 1
b 0
f 1
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createExceptionId() 0 7 1
A __construct() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\SemanticLog;
6
7
use Koriym\SemanticLogger\AbstractContext;
8
9
use function crc32;
10
use function dechex;
11
12
/** @deprecated Use BEAR\Resource\SemanticLog\Profile\Compact\ErrorContext instead */
13
final class ResourceErrorContext 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/bear-resource-error.json';
20
21
    public readonly string $exceptionId;
22
23
    public function __construct(public readonly string $exceptionClass, public readonly string $exceptionMessage, string $exceptionId = '')
24
    {
25
        $this->exceptionId = $exceptionId !== '' ? $exceptionId : $this->createExceptionId();
0 ignored issues
show
Bug introduced by
The property exceptionId is declared read-only in BEAR\Resource\SemanticLog\ResourceErrorContext.
Loading history...
26
    }
27
28
    private function createExceptionId(): string
29
    {
30
        $content = $this->exceptionClass . ':' . $this->exceptionMessage;
31
        $crc = crc32($content);
32
        $crcHex = dechex($crc & 0xFFFFFFFF);
33
34
        return 'e-bear-resource-' . $crcHex;
35
    }
36
}
37