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

PriceList::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 0
c 2
b 0
f 2
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Level23\Dynadot\Dto;
4
5
final class PriceList implements DtoInterface
6
{
7
    public string $currency;
8
    public string $unit;
9
    public string $transfer;
10
    public string $restore;
11
    public string $registration;
12
    public string $renewal;
13
14 6
    private function __construct()
15
    {
16 6
    }
17
18
    /**
19
     * Hydrate from Dynadot's response data.
20
     *
21
     * @param array<string,mixed> $data
22
     * @return self
23
     */
24 6
    public static function fromArray(array $data): self
25
    {
26 6
        $dto               = new self();
27 6
        $dto->currency     = $data['currency'] ?? '';
28 6
        $dto->unit         = $data['unit'] ?? '';
29 6
        $dto->registration = $data['registration'] ?? '';
30 6
        $dto->renewal      = $data['renewal'] ?? '';
31 6
        $dto->transfer     = $data['transfer'] ?? '';
32 6
        $dto->restore      = $data['restore'] ?? '';
33
34 6
        return $dto;
35
    }
36
37
    /**
38
     * @return array<string, mixed>
39
     */
40
    public function jsonSerialize(): array
41
    {
42
        return [
43
            'currency'     => $this->currency,
44
            'unit'         => $this->unit,
45
            'transfer'     => $this->transfer,
46
            'restore'      => $this->restore,
47
            'registration' => $this->registration,
48
            'renewal'      => $this->renewal,
49
        ];
50
    }
51
}
52