Passed
Pull Request — master (#10)
by
unknown
02:50
created

DomainInfo::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 21
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 23
ccs 22
cts 22
cp 1
crap 1
rs 9.584
1
<?php
2
3
namespace Level23\Dynadot\Dto;
4
5
final class DomainInfo implements DtoInterface
6
{
7
    public string $domainName;
8
    public int $expiration;
9
    public int $registration;
10
    /** @var array<string, string> */
11
    public array $glueInfo;
12
    public int $registrantContactId;
13
    public int $adminContactId;
14
    public int $techContactId;
15
    public int $billingContactId;
16
    public bool $locked;
17
    public bool $disabled;
18
    public bool $udrpLocked;
19
    public bool $registrantUnverified;
20
    public bool $hold;
21
    public string $privacy;
22
    public bool $isForSale;
23
    public string $renewOption;
24
    public ?string $note;
25
    public int $folderId;
26
    public string $folderName;
27
    public string $status;
28
29
    /**
30
     * @param array<string, string> $glueInfo
31
     */
32 2
    private function __construct(
33
        string $domainName,
34
        int $expiration,
35
        int $registration,
36
        array $glueInfo,
37
        int $registrantContactId,
38
        int $adminContactId,
39
        int $techContactId,
40
        int $billingContactId,
41
        bool $locked,
42
        bool $disabled,
43
        bool $udrpLocked,
44
        bool $registrantUnverified,
45
        bool $hold,
46
        string $privacy,
47
        bool $isForSale,
48
        string $renewOption,
49
        ?string $note,
50
        int $folderId,
51
        string $folderName,
52
        string $status,
53
    ) {
54 2
        $this->domainName           = $domainName;
55 2
        $this->expiration           = $expiration;
56 2
        $this->registration         = $registration;
57 2
        $this->glueInfo             = $glueInfo;
58 2
        $this->registrantContactId  = $registrantContactId;
59 2
        $this->adminContactId       = $adminContactId;
60 2
        $this->techContactId        = $techContactId;
61 2
        $this->billingContactId     = $billingContactId;
62 2
        $this->locked               = $locked;
63 2
        $this->disabled             = $disabled;
64 2
        $this->udrpLocked           = $udrpLocked;
65 2
        $this->registrantUnverified = $registrantUnverified;
66 2
        $this->hold                 = $hold;
67 2
        $this->privacy              = $privacy;
68 2
        $this->isForSale            = $isForSale;
69 2
        $this->renewOption          = $renewOption;
70 2
        $this->note                 = $note;
71 2
        $this->folderId             = $folderId;
72 2
        $this->folderName           = $folderName;
73 2
        $this->status               = $status;
74
    }
75
76
    /**
77
     * Hydrate from domain data.
78
     *
79
     * @param array<string,mixed> $data
80
     * @return self
81
     */
82 2
    public static function fromArray(array $data): self
83
    {
84 2
        return new self(
85 2
            $data['domainName'],
86 2
            $data['expiration'],
87 2
            $data['registration'],
88 2
            $data['glueInfo'],
89 2
            $data['registrant_contactId'],
90 2
            $data['admin_contactId'],
91 2
            $data['tech_contactId'],
92 2
            $data['billing_contactId'],
93 2
            $data['locked'],
94 2
            $data['disabled'],
95 2
            $data['udrpLocked'],
96 2
            $data['registrant_unverified'] ?? false,
97 2
            $data['hold'],
98 2
            $data['privacy'],
99 2
            $data['is_for_sale'],
100 2
            $data['renew_option'],
101 2
            $data['note'],
102 2
            $data['folder_id'],
103 2
            $data['folder_name'],
104 2
            $data['status'],
105 2
        );
106
    }
107
108
    /**
109
     * @return array<string, mixed>
110
     */
111
    public function jsonSerialize(): array
112
    {
113
        return [
114
            'domainName'            => $this->domainName,
115
            'expiration'            => $this->expiration,
116
            'registration'          => $this->registration,
117
            'glueInfo'              => $this->glueInfo,
118
            'registrant_contact_id' => $this->registrantContactId,
119
            'admin_contact_id'      => $this->adminContactId,
120
            'tech_contact_id'       => $this->techContactId,
121
            'billing_contact_id'    => $this->billingContactId,
122
            'locked'                => $this->locked,
123
            'disabled'              => $this->disabled,
124
            'udrp_locked'           => $this->udrpLocked,
125
            'registrant_unverified' => $this->registrantUnverified,
126
            'hold'                  => $this->hold,
127
            'privacy'               => $this->privacy,
128
            'is_for_sale'           => $this->isForSale,
129
            'renew_option'          => $this->renewOption,
130
            'note'                  => $this->note,
131
            'folder_id'             => $this->folderId,
132
            'folder_name'           => $this->folderName,
133
            'status'                => $this->status,
134
        ];
135
    }
136
}
137