Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
47.92% covered (danger)
47.92%
23 / 48
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ErrorLogData
47.92% covered (danger)
47.92%
23 / 48
50.00% covered (danger)
50.00%
1 / 2
2.57
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\ErrorLog\Data;
6
7use App\Support\Row;
8use JsonSerializable;
9
10/**
11 * Data transfer object for error log entries.
12 */
13final class ErrorLogData implements JsonSerializable
14{
15    public int $errorId;
16
17    public string $level;
18
19    public int $levelValue;
20
21    public ?string $errorCode;
22
23    public string $message;
24
25    public ?string $stackTrace;
26
27    public ?string $requestUri;
28
29    public ?string $requestMethod;
30
31    public ?int $userId;
32
33    public ?string $username;
34
35    public ?string $userEmail;
36
37    public ?int $sessionId;
38
39    public ?string $sessionCreatedAt;
40
41    public ?string $ipAddress;
42
43    public ?string $userAgent;
44
45    /** @var array<mixed>|null */
46    public ?array $requestBody;
47
48    /** @var array<mixed>|null */
49    public ?array $context;
50
51    public ?string $resolvedAt;
52
53    public ?int $resolvedBy;
54
55    public ?string $resolvedByUsername;
56
57    public ?string $resolutionNotes;
58
59    public string $createdAt;
60
61    public bool $isResolved;
62
63    /**
64     * @param array<mixed> $data
65     */
66    public function __construct(array $data)
67    {
68        $this->errorId = Row::int($data, 'errorId');
69        $this->level = Row::string($data, 'level');
70        $this->levelValue = Row::int($data, 'levelValue');
71        $this->errorCode = Row::nullableString($data, 'errorCode');
72        $this->message = Row::string($data, 'message');
73        $this->stackTrace = Row::nullableString($data, 'stackTrace');
74        $this->requestUri = Row::nullableString($data, 'requestUri');
75        $this->requestMethod = Row::nullableString($data, 'requestMethod');
76        $this->userId = Row::nullableInt($data, 'userId');
77        $this->username = Row::nullableString($data, 'username');
78        $this->userEmail = Row::nullableString($data, 'userEmail');
79        $this->sessionId = Row::nullableInt($data, 'sessionId');
80        $this->sessionCreatedAt = Row::nullableString($data, 'sessionCreatedAt');
81        $this->ipAddress = Row::nullableString($data, 'ipAddress');
82        $this->userAgent = Row::nullableString($data, 'userAgent');
83        $this->requestBody = Row::nullableArray($data, 'requestBody');
84        $this->context = Row::nullableArray($data, 'context');
85        $this->resolvedAt = Row::nullableString($data, 'resolvedAt');
86        $this->resolvedBy = Row::nullableInt($data, 'resolvedBy');
87        $this->resolvedByUsername = Row::nullableString($data, 'resolvedByUsername');
88        $this->resolutionNotes = Row::nullableString($data, 'resolutionNotes');
89        $this->createdAt = Row::string($data, 'createdAt');
90        $this->isResolved = Row::nullableBool($data, 'isResolved') ?? false;
91    }
92
93    /**
94     * @return array<string, mixed>
95     */
96    public function jsonSerialize(): array
97    {
98        return [
99            'errorId' => $this->errorId,
100            'level' => $this->level,
101            'levelValue' => $this->levelValue,
102            'errorCode' => $this->errorCode,
103            'message' => $this->message,
104            'stackTrace' => $this->stackTrace,
105            'requestUri' => $this->requestUri,
106            'requestMethod' => $this->requestMethod,
107            'userId' => $this->userId,
108            'username' => $this->username,
109            'userEmail' => $this->userEmail,
110            'sessionId' => $this->sessionId,
111            'sessionCreatedAt' => $this->sessionCreatedAt,
112            'ipAddress' => $this->ipAddress,
113            'userAgent' => $this->userAgent,
114            'requestBody' => $this->requestBody,
115            'context' => $this->context,
116            'resolvedAt' => $this->resolvedAt,
117            'resolvedBy' => $this->resolvedBy,
118            'resolvedByUsername' => $this->resolvedByUsername,
119            'resolutionNotes' => $this->resolutionNotes,
120            'createdAt' => $this->createdAt,
121            'isResolved' => $this->isResolved,
122        ];
123    }
124}