DefaultNameServerSettings::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 7
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Level23\Dynadot\Dto;
4
5
final class DefaultNameServerSettings implements DtoInterface
6
{
7
    public string $type;
8
    public string $withAds;
9
    public string $forwardTo;
10
    public string $forwardType;
11
    public string $websiteTitle;
12
    public string $ttl;
13
    public EmailForwarding $emailForwarding;
14
15 1
    public function __construct(
16
        string $type = '',
17
        string $withAds = '',
18
        string $forwardTo = '',
19
        string $forwardType = '',
20
        string $websiteTitle = '',
21
        string $ttl = '',
22
        ?EmailForwarding $emailForwarding = null
23
    ) {
24 1
        $this->type            = $type;
25 1
        $this->withAds         = $withAds;
26 1
        $this->forwardTo       = $forwardTo;
27 1
        $this->forwardType     = $forwardType;
28 1
        $this->websiteTitle    = $websiteTitle;
29 1
        $this->ttl             = $ttl;
30 1
        $this->emailForwarding = $emailForwarding ?? new EmailForwarding();
31
    }
32
33 1
    public static function fromArray(array $data): self
34
    {
35 1
        return new self(
36 1
            $data['type'] ?? '',
37 1
            $data['with_ads'] ?? '',
38 1
            $data['forward_to'] ?? '',
39 1
            $data['forward_type'] ?? '',
40 1
            $data['website_title'] ?? '',
41 1
            $data['ttl'] ?? '',
42 1
            isset($data['email_forwarding']) ? EmailForwarding::fromArray($data['email_forwarding']) : new EmailForwarding()
43 1
        );
44
    }
45
46
    /**
47
     * @return array<string, mixed>
48
     */
49
    public function jsonSerialize(): array
50
    {
51
        return [
52
            'type'             => $this->type,
53
            'with_ads'         => $this->withAds,
54
            'forward_to'       => $this->forwardTo,
55
            'forward_type'     => $this->forwardType,
56
            'website_title'    => $this->websiteTitle,
57
            'ttl'              => $this->ttl,
58
            'email_forwarding' => $this->emailForwarding->jsonSerialize(),
59
        ];
60
    }
61
}
62