Completed
Push — master ( 5836e1...99cc50 )
by Sam
15s queued 10s
created

APL::outputFormatted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Badcow\DNS\Rdata;
4
5
class APL implements RdataInterface
6
{
7
    use RdataTrait;
8
9
    const TYPE = 'APL';
10
11
    /**
12
     * @var \IPBlock[]
13
     */
14
    private $includedAddressRanges = [];
15
16
    /**
17
     * @var \IPBlock[]
18
     */
19
    private $excludedAddressRanges = [];
20
21
    /**
22
     * @param \IPBlock $ipBlock
23
     * @param bool     $included True if the resource exists within the range, False if the resource
24
     *                           is not within the range. I.E. the negation.
25
     */
26 1
    public function addAddressRange(\IPBlock $ipBlock, $included = true): void
27
    {
28 1
        if ($included) {
29 1
            $this->includedAddressRanges[] = $ipBlock;
30
        } else {
31 1
            $this->excludedAddressRanges[] = $ipBlock;
32
        }
33 1
    }
34
35
    /**
36
     * @return \IPBlock[]
37
     */
38
    public function getIncludedAddressRanges(): array
39
    {
40
        return $this->includedAddressRanges;
41
    }
42
43
    /**
44
     * @return \IPBlock[]
45
     */
46
    public function getExcludedAddressRanges(): array
47
    {
48
        return $this->excludedAddressRanges;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function output(): string
55
    {
56 1
        $string = '';
57 1
        foreach ($this->includedAddressRanges as $ipBlock) {
58 1
            $string .= (4 === $ipBlock->getVersion()) ? '1:' : '2:';
59 1
            $string .= (string) $ipBlock.' ';
60
        }
61
62 1
        foreach ($this->excludedAddressRanges as $ipBlock) {
63 1
            $string .= (4 === $ipBlock->getVersion()) ? '!1:' : '!2:';
64 1
            $string .= (string) $ipBlock.' ';
65
        }
66
67 1
        return rtrim($string, ' ');
68
    }
69
}
70