Completed
Push — master ( 40e48e...230698 )
by Sam
02:25
created

SrvRdata::getPriority()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of Badcow DNS Library.
5
 *
6
 * (c) Samuel Williams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Badcow\DNS\Rdata;
13
14
class SrvRdata extends CnameRdata
15
{
16
    const TYPE = 'SRV';
17
18
    const HIGHEST_PORT = 65535;
19
20
    const MAX_PRIORITY = 65535;
21
22
    const MAX_WEIGHT = 65535;
23
24
    /**
25
     * The priority of this target host. A client MUST attempt to
26
     * contact the target host with the lowest-numbered priority it can
27
     * reach; target hosts with the same priority SHOULD be tried in an
28
     * order defined by the weight field. The range is 0-65535. This
29
     * is a 16 bit unsigned integer.
30
     *
31
     * @var int
32
     */
33
    private $priority;
34
35
    /**
36
     * A server selection mechanism.  The weight field specifies a
37
     * relative weight for entries with the same priority. The range
38
     * is 0-65535. This is a 16 bit unsigned integer.
39
     *
40
     * @var int
41
     */
42
    private $weight;
43
44
    /**
45
     * The port on this target host of this service. The range is
46
     * 0-65535. This is a 16 bit unsigned integer
47
     *
48
     * @var int
49
     */
50
    private $port;
51
52
    /**
53
     * @return int
54
     */
55
    public function getPriority()
56
    {
57
        return $this->priority;
58
    }
59
60
    /**
61
     * @param int $priority
62
     * @throws \InvalidArgumentException
63
     */
64 3
    public function setPriority($priority)
65
    {
66 3
        if ($priority < 0 || $priority > static::MAX_PRIORITY) {
67
            throw new \InvalidArgumentException('Priority must be an unsigned integer on the range [0-65535]');
68
        }
69
70 3
        $this->priority = (int)$priority;
71 3
    }
72
73
    /**
74
     * @return int
75
     */
76
    public function getWeight()
77
    {
78
        return $this->weight;
79
    }
80
81
    /**
82
     * @param int $weight
83
     * @throws \InvalidArgumentException
84
     */
85 3
    public function setWeight($weight)
86
    {
87 3
        if ($weight < 0 || $weight > static::MAX_WEIGHT) {
88
            throw new \InvalidArgumentException('Weight must be an unsigned integer on the range [0-65535]');
89
        }
90
91 3
        $this->weight = $weight;
92 3
    }
93
94
    /**
95
     * @return int
96
     */
97
    public function getPort()
98
    {
99
        return $this->port;
100
    }
101
102
    /**
103
     * @param int $port
104
     * @throws \InvalidArgumentException
105
     */
106 3
    public function setPort($port)
107
    {
108 3
        if ($port < 0 || $port > static::HIGHEST_PORT) {
109
            throw new \InvalidArgumentException('Port must be an unsigned integer on the range [0-65535]');
110
        }
111
112 3
        $this->port = $port;
113 3
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118 3
    public function output()
119
    {
120 3
        return sprintf('%s %s %s %s',
121 3
            $this->priority,
122 3
            $this->weight,
123 3
            $this->port,
124 3
            $this->target
125 2
        );
126
    }
127
}