Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PandaDocTemplateFieldData
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fromPandaDocResponse
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 toArray
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\Document\Data;
6
7use App\Support\Row;
8
9final readonly class PandaDocTemplateFieldData
10{
11    public function __construct(
12        public string $name,
13        public string $type,
14        public ?string $title = null,
15        public ?string $assignedTo = null,
16    ) {}
17
18    /**
19     * @param array<mixed> $field
20     */
21    public static function fromPandaDocResponse(array $field): self
22    {
23        $assignedTo = null;
24        $assigned = $field['assigned_to'] ?? null;
25        if (is_array($assigned)) {
26            $assignedTo = Row::nullableString($assigned, 'name')
27                ?? Row::nullableString($assigned, 'email');
28        }
29
30        return new self(
31            name: Row::nullableString($field, 'name') ?? '',
32            type: Row::nullableString($field, 'type') ?? '',
33            title: Row::nullableString($field, 'title'),
34            assignedTo: $assignedTo,
35        );
36    }
37
38    /**
39     * @return array<string, mixed>
40     */
41    public function toArray(): array
42    {
43        return [
44            'name' => $this->name,
45            'type' => $this->type,
46            'title' => $this->title,
47            'assignedTo' => $this->assignedTo,
48        ];
49    }
50}