DomainInfo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 20
c 2
b 0
f 2
nc 1
nop 20
dl 0
loc 42
ccs 21
cts 21
cp 1
crap 1
rs 9.6

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 4
    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 4
        $this->domainName           = $domainName;
55 4
        $this->expiration           = $expiration;
56 4
        $this->registration         = $registration;
57 4
        $this->glueInfo             = $glueInfo;
58 4
        $this->registrantContactId  = $registrantContactId;
59 4
        $this->adminContactId       = $adminContactId;
60 4
        $this->techContactId        = $techContactId;
61 4
        $this->billingContactId     = $billingContactId;
62 4
        $this->locked               = $locked;
63 4
        $this->disabled             = $disabled;
64 4
        $this->udrpLocked           = $udrpLocked;
65 4
        $this->registrantUnverified = $registrantUnverified;
66 4
        $this->hold                 = $hold;
67 4
        $this->privacy              = $privacy;
68 4
        $this->isForSale            = $isForSale;
69 4
        $this->renewOption          = $renewOption;
70 4
        $this->note                 = $note;
71 4
        $this->folderId             = $folderId;
72 4
        $this->folderName           = $folderName;
73 4
        $this->status               = $status;
74
    }
75
76
    /**
77
     * Hydrate from domain data.
78
     *
79
     * @param array<string,mixed> $data
80
     * @return self
81
     */
82 4
    public static function fromArray(array $data): self
83
    {
84 4
        return new self(
85 4
            $data['domainName'],
86 4
            $data['expiration'],
87 4
            $data['registration'],
88 4
            $data['glueInfo'],
89 4
            $data['registrant_contactId'],
90 4
            $data['admin_contactId'],
91 4
            $data['tech_contactId'],
92 4
            $data['billing_contactId'],
93 4
            $data['locked'],
94 4
            $data['disabled'],
95 4
            $data['udrpLocked'],
96 4
            $data['registrant_unverified'] ?? false,
97 4
            $data['hold'],
98 4
            $data['privacy'],
99 4
            $data['is_for_sale'],
100 4
            $data['renew_option'],
101 4
            $data['note'],
102 4
            $data['folder_id'],
103 4
            $data['folder_name'],
104 4
            $data['status'],
105 4
        );
106
    }
107
108
    /**
109
     * @return array<string, mixed>
110
     */
111 2
    public function jsonSerialize(): array
112
    {
113 2
        return [
114 2
            'domainName'            => $this->domainName,
115 2
            'expiration'            => $this->expiration,
116 2
            'registration'          => $this->registration,
117 2
            'glueInfo'              => $this->glueInfo,
118 2
            'registrant_contact_id' => $this->registrantContactId,
119 2
            'admin_contact_id'      => $this->adminContactId,
120 2
            'tech_contact_id'       => $this->techContactId,
121 2
            'billing_contact_id'    => $this->billingContactId,
122 2
            'locked'                => $this->locked,
123 2
            'disabled'              => $this->disabled,
124 2
            'udrp_locked'           => $this->udrpLocked,
125 2
            'registrant_unverified' => $this->registrantUnverified,
126 2
            'hold'                  => $this->hold,
127 2
            'privacy'               => $this->privacy,
128 2
            'is_for_sale'           => $this->isForSale,
129 2
            'renew_option'          => $this->renewOption,
130 2
            'note'                  => $this->note,
131 2
            'folder_id'             => $this->folderId,
132 2
            'folder_name'           => $this->folderName,
133 2
            'status'                => $this->status,
134 2
        ];
135
    }
136
}
137