Passed
Branch master (cc9218)
by Christian
02:27
created

SRVData::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Entities;
4
5
class SRVData extends DataAbstract
6
{
7
    /**
8
     * @var int
9
     */
10
    private $priority;
11
12
    /**
13
     * @var int
14
     */
15
    private $weight;
16
17
    /**
18
     * @var int
19
     */
20
    private $port;
21
22
    /**
23
     * @var \RemotelyLiving\PHPDNS\Entities\Hostname
24
     */
25
    private $target;
26
27
    public function __construct(int $priority, int $weight, int $port, Hostname $target)
28
    {
29
        $this->priority = $priority;
30
        $this->weight = $weight;
31
        $this->port = $port;
32
        $this->target = $target;
33
    }
34
35
    public function __toString(): string
36
    {
37
        return "{$this->priority} {$this->weight} {$this->port} {$this->target}";
38
    }
39
40
    public function getPriority(): int
41
    {
42
        return $this->priority;
43
    }
44
45
    public function getWeight(): int
46
    {
47
        return $this->weight;
48
    }
49
50
    public function getPort(): int
51
    {
52
        return $this->port;
53
    }
54
55
    public function getTarget(): Hostname
56
    {
57
        return $this->target;
58
    }
59
60
    public function toArray(): array
61
    {
62
        return [
63
            'priority' => $this->priority,
64
            'weight'  => $this->weight,
65
            'port'    => $this->port,
66
            'target' => (string)$this->target,
67
        ];
68
    }
69
70
    public function serialize(): string
71
    {
72
        return \serialize($this->toArray());
73
    }
74
75
    /**
76
     * @param string $serialized
77
     */
78
    public function unserialize($serialized): void
79
    {
80
        $unserialized = \unserialize($serialized);
81
        $this->priority = $unserialized['priority'];
82
        $this->weight = $unserialized['weight'];
83
        $this->port = $unserialized['port'];
84
        $this->target = new Hostname($unserialized['target']);
85
    }
86
}
87