ContactListResult   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 10
c 2
b 0
f 2
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromArray() 0 11 4
A jsonSerialize() 0 4 1
1
<?php
2
3
namespace Level23\Dynadot\Dto;
4
5
final class ContactListResult implements DtoInterface
6
{
7
    /** @var array<Contact> */
8
    public array $contacts;
9
10
    /**
11
     * @param array<Contact> $contacts
12
     */
13 7
    private function __construct(array $contacts)
14
    {
15 7
        $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 7
    public static function fromArray(array $data): self
25
    {
26 7
        $contacts = [];
27
28 7
        if (isset($data['contact_list']) && is_array($data['contact_list'])) {
29 5
            foreach ($data['contact_list'] as $contactData) {
30 4
                $contacts[] = Contact::fromArray($contactData);
31
            }
32
        }
33
34 7
        return new self($contacts);
35
    }
36
37
    /**
38
     * @return array<string, mixed>
39
     */
40 1
    public function jsonSerialize(): array
41
    {
42 1
        return [
43 1
            'contact_list' => array_map(fn ($contact) => $contact->jsonSerialize(), $this->contacts),
44 1
        ];
45
    }
46
}
47