Completed
Pull Request — master (#5)
by Christian
02:05
created

SOAData::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
namespace RemotelyLiving\PHPDNS\Entities;
3
4
class SOAData extends DataAbstract
5
{
6
    /**
7
     * @var \RemotelyLiving\PHPDNS\Entities\Hostname
8
     */
9
    private $mname;
10
11
    /**
12
     * @var \RemotelyLiving\PHPDNS\Entities\Hostname
13
     */
14
    private $rname;
15
16
    /**
17
     * @var int
18
     */
19
    private $serial;
20
21
    /**
22
     * @var int
23
     */
24
    private $refresh;
25
26
    /**
27
     * @var int
28
     */
29
    private $retry;
30
31
    /**
32
     * @var int
33
     */
34
    private $expire;
35
36
    /**
37
     * @var int
38
     */
39
    private $minTTL;
40
41
    public function __construct(
42
        Hostname $mname,
43
        Hostname $rname,
44
        int $serial,
45
        int $refresh,
46
        int $retry,
47
        int $expire,
48
        int $minTTL
49
    ) {
50
        $this->mname = $mname;
51
        $this->rname = $rname;
52
        $this->serial = $serial;
53
        $this->refresh = $refresh;
54
        $this->retry = $retry;
55
        $this->expire = $expire;
56
        $this->minTTL = $minTTL;
57
    }
58
59
    public function __toString(): string
60
    {
61
        $template = '%s %s %s %s %s %s %s';
62
        return vsprintf($template, $this->toArray());
63
    }
64
65
    /**
66
     * @return \RemotelyLiving\PHPDNS\Entities\Hostname
67
     */
68
    public function getMname(): Hostname
69
    {
70
        return $this->mname;
71
    }
72
73
    /**
74
     * @return \RemotelyLiving\PHPDNS\Entities\Hostname
75
     */
76
    public function getRname(): Hostname
77
    {
78
        return $this->rname;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function getSerial(): int
85
    {
86
        return $this->serial;
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function getRefresh(): int
93
    {
94
        return $this->refresh;
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getRetry(): int
101
    {
102
        return $this->retry;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getExpire(): int
109
    {
110
        return $this->expire;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getMinTTL(): int
117
    {
118
        return $this->minTTL;
119
    }
120
121
122
    public function toArray(): array
123
    {
124
        return [
125
            'mname' => (string)$this->mname,
126
            'rname' => (string)$this->rname,
127
            'serial' => $this->serial,
128
            'refresh' => $this->refresh,
129
            'retry' => $this->retry,
130
            'expire' => $this->expire,
131
            'minimumTTL' => $this->minTTL,
132
        ];
133
    }
134
135
    public function serialize(): string
136
    {
137
        return \serialize($this->toArray());
138
    }
139
140
    public function unserialize($serialized): void
141
    {
142
        $unserialized = \unserialize($serialized);
143
        $this->mname = new Hostname($unserialized['mname']);
144
        $this->rname = new Hostname($unserialized['rname']);
145
        $this->serial = $unserialized['serial'];
146
        $this->refresh = $unserialized['refresh'];
147
        $this->retry = $unserialized['retry'];
148
        $this->expire = $unserialized['expire'];
149
        $this->minTTL = $unserialized['minimumTTL'];
150
    }
151
}
152