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

ResourceErrorContext::createExceptionId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
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