Lines 80.00% 12 / 15
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 toArray 78.57% 11 / 14 0.00% 0 / 1 4.16
22final readonly class ProblemDetails
23{
24    /* @mago-expect lint:excessive-parameter-list - mirrors the RFC 7807 problem-details fields */
25    public function __construct(
26        public string $type,
27        public string $title,
28        public int $status,
29        public string $detail,
30        public string $instance,
31        public ?string $code = null,
32        public ?array $errors = null, // field-level errors, optional
33        public ?string $traceId = null, // correlation id, optional
34    ) {
35    }
36
37    public function toArray(): array
38    {
39        $data = [
40            'type' => $this->type,
41            'title' => $this->title,
42            'status' => $this->status,
43            'detail' => $this->detail,
44            'instance' => $this->instance,
45        ];
46
47        if ($this->code !== null) {
48            $data['code'] = $this->code;
49        }
50
51        if ($this->errors !== null) {
52            $data['errors'] = $this->errors;
53        }
54
55        if ($this->traceId !== null) {
56            $data['traceId'] = $this->traceId;
57        }
58
59        return $data;
60    }
61}