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

MXData::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace RemotelyLiving\PHPDNS\Entities;
3
4
class MXData extends DataAbstract
5
{
6
    /**
7
     * @var \RemotelyLiving\PHPDNS\Entities\Hostname
8
     */
9
    private $target;
10
11
    /**
12
     * @var int
13
     */
14
    private $priority;
15
16
    public function __construct(Hostname $target, int $priority = 0)
17
    {
18
        $this->target = $target;
19
        $this->priority = $priority;
20
    }
21
22
    public function __toString(): string
23
    {
24
        return "{$this->priority} {$this->target}";
25
    }
26
27
    public function getTarget(): Hostname
28
    {
29
        return $this->target;
30
    }
31
32
    public function getPriority(): int
33
    {
34
        return $this->priority;
35
    }
36
37
    public function toArray(): array
38
    {
39
        return [
40
            'target' => (string)$this->target,
41
            'priority' => $this->priority,
42
        ];
43
    }
44
45
    public function serialize(): string
46
    {
47
        return \serialize($this->toArray());
48
    }
49
50
    public function unserialize($serialized): void
51
    {
52
        $unserialized = \unserialize($serialized);
53
        $this->target = new Hostname($unserialized['target']);
54
        $this->priority = $unserialized['priority'];
55
    }
56
}
57