Completed
Push — master ( 546b84...666d36 )
by Sam
01:38
created

CAA::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
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
/**
15
 * Class CaaRdata.
16
 *
17
 * CAA is defined in RFC 6844
18
 *
19
 * @see https://tools.ietf.org/html/rfc6844
20
 *
21
 * @author Samuel Williams <[email protected]>
22
 */
23
class CAA implements RdataInterface
24
{
25
    use RdataTrait;
26
27
    const TYPE = 'CAA';
28
29
    const MAX_FLAG = 255;
30
31
    const TAG_ISSUE = 'issue';
32
33
    const TAG_ISSUEWILD = 'issuewild';
34
35
    const TAG_IODEF = 'iodef';
36
37
    const ALLOWED_TAGS = [self::TAG_ISSUE, self::TAG_ISSUEWILD, self::TAG_IODEF];
38
39
    /**
40
     * It is currently used to represent the critical flag
41
     *
42
     * @var int
43
     */
44
    private $flag;
45
46
    /**
47
     * An ASCII string that represents the identifier of the property represented by the record.
48
     * The RFC currently defines 3 available tags:
49
     *  - issue: explicity authorizes a single certificate authority to issue a certificate (any type) for the hostname.
50
     *  - issuewild: explicity authorizes a single certificate authority to issue a wildcard certificate (and only wildcard) for the hostname.
51
     *  - iodef: specifies a URL to which a certificate authority may report policy violations.
52
     *
53
     * @var string
54
     */
55
    private $tag;
56
57
    /**
58
     * @var string
59
     */
60
    private $value;
61
62
    /**
63
     * @return int
64
     */
65 1
    public function getFlag(): ?int
66
    {
67 1
        return $this->flag;
68
    }
69
70
    /**
71
     * @param int $flag
72
     *
73
     * @throws \InvalidArgumentException
74
     */
75 2
    public function setFlag(int $flag): void
76
    {
77 2
        if ($flag < 0 || $flag > static::MAX_FLAG) {
78 1
            throw new \InvalidArgumentException('Flag must be an unsigned integer on the range [0-255]');
79
        }
80
81 1
        $this->flag = $flag;
82 1
    }
83
84
    /**
85
     * @return string
86
     */
87 1
    public function getTag(): ?string
88
    {
89 1
        return $this->tag;
90
    }
91
92
    /**
93
     * @param string $tag
94
     *
95
     * @throws \InvalidArgumentException
96
     */
97 2
    public function setTag(string $tag): void
98
    {
99 2
        if (!in_array($tag, static::ALLOWED_TAGS)) {
100 1
            throw new \InvalidArgumentException('Tag can be one of this type '.implode(' ', static::ALLOWED_TAGS));
101
        }
102
103 1
        $this->tag = $tag;
104 1
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getValue(): string
110
    {
111
        return $this->value;
112
    }
113
114
    /**
115
     * @param string $value
116
     */
117 1
    public function setValue(string $value): void
118
    {
119 1
        $this->value = $value;
120 1
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 1
    public function output(): string
126
    {
127 1
        return sprintf('%s %s "%s"',
128 1
            $this->flag,
129 1
            $this->tag,
130 1
            $this->value
131
        );
132
    }
133
}
134