Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 72.72% |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
5 | final class ContactListResult implements DtoInterface |
||
6 | { |
||
7 | /** @var array<Contact> */ |
||
8 | public array $contacts; |
||
9 | |||
10 | /** |
||
11 | * @param array<Contact> $contacts |
||
12 | */ |
||
13 | 6 | private function __construct(array $contacts) |
|
14 | { |
||
15 | 6 | $this->contacts = $contacts; |
|
16 | } |
||
17 | |||
18 | /** |
||
19 | * Hydrate from Dynadot's response "Data" object. |
||
20 | * |
||
21 | * @param array<string,mixed> $data |
||
22 | * @return self |
||
23 | */ |
||
24 | 6 | public static function fromArray(array $data): self |
|
25 | { |
||
26 | 6 | $contacts = []; |
|
27 | |||
28 | 6 | if (isset($data['contact_list']) && is_array($data['contact_list'])) { |
|
29 | 4 | foreach ($data['contact_list'] as $contactData) { |
|
30 | 3 | $contacts[] = Contact::fromArray($contactData); |
|
31 | } |
||
32 | } |
||
33 | |||
34 | 6 | return new self($contacts); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return array<string, mixed> |
||
39 | */ |
||
40 | public function jsonSerialize(): array |
||
44 | ]; |
||
45 | } |
||
46 | } |
||
47 |