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

MXData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A toArray() 0 5 1
A unserialize() 0 5 1
A serialize() 0 3 1
A getTarget() 0 3 1
A getPriority() 0 3 1
A __construct() 0 4 1
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