Passed
Pull Request — master (#11)
by
unknown
02:34
created

DomainRegistrationResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromArray() 0 5 1
A jsonSerialize() 0 5 1
1
<?php
2
3
namespace Level23\Dynadot\Dto;
4
5
final class DomainRegistrationResult implements DtoInterface
6
{
7
    public string $domainName;
8
    public int $expirationDate;
9
10 9
    private function __construct(
11
        string $domainName,
12
        int $expirationDate,
13
    ) {
14 9
        $this->domainName     = $domainName;
15 9
        $this->expirationDate = $expirationDate;
16
    }
17
18
    /**
19
     * Hydrate from Dynadot's response data.
20
     *
21
     * @param array<string,mixed> $data
22
     * @return self
23
     */
24 9
    public static function fromArray(array $data): self
25
    {
26 9
        return new self(
27 9
            $data['domain_name'] ?? '',
28 9
            $data['expiration_date'] ?? 0,
29 9
        );
30
    }
31
32
    /**
33
     * @return array<string, mixed>
34
     */
35 1
    public function jsonSerialize(): array
36
    {
37 1
        return [
38 1
            'domain_name'     => $this->domainName,
39 1
            'expiration_date' => $this->expirationDate,
40 1
        ];
41
    }
42
}
43