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

APL   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 65
ccs 14
cts 18
cp 0.7778
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addAddressRange() 0 8 2
A getIncludedAddressRanges() 0 4 1
A getExcludedAddressRanges() 0 4 1
A output() 0 15 5
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