Completed
Push — master ( ece0e5...b20eda )
by Peter
02:27
created

IPv6NetworkComparator::abuts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2016, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Interval\IPv6Network;
12
13
/**
14
 * The comparator must be used only in IPv6Network.
15
 */
16 View Code Duplication
class IPv6NetworkComparator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var IPv6Network
20
     */
21
    private $network;
22
23
    /**
24
     * @param IPv6Network $network
25
     */
26 17
    public function __construct(IPv6Network $network)
27
    {
28 17
        $this->network = $network;
29 17
    }
30
31
    /**
32
     * Checks if this network is equal to the specified network.
33
     *
34
     * @param IPv6Network $interval
35
     *
36
     * @return bool
37
     */
38
    public function equal(IPv6Network $interval)
39
    {
40
        return
41
            $this->network->startPoint()->eq($interval->startPoint()) &&
42
            $this->network->mask() == $interval->mask()
43
        ;
44
    }
45
46
    /**
47
     * Does this network contain the specified IP.
48
     *
49
     * @param IPv6NetworkPoint $point
50
     *
51
     * @return bool
52
     */
53 2
    public function contains(IPv6NetworkPoint $point)
54
    {
55
        return
56 2
            $this->network->startPoint()->lte($point) &&
57 2
            $this->network->endPoint()->gte($point)
58 2
        ;
59
    }
60
61
    /**
62
     * Does this network intersect the specified network.
63
     *
64
     * @param IPv6Network $network
65
     *
66
     * @return bool
67
     */
68 3
    public function intersects(IPv6Network $network)
69
    {
70
        if (
71 3
            $this->network->startPoint()->gt($network->endPoint()) ||
72 3
            $this->network->endPoint()->lt($network->startPoint())
73 3
        ) {
74 1
            return false;
75
        }
76
77 2
        return true;
78
    }
79
80
    /**
81
     * Does this network abut with the network specified.
82
     *
83
     * @param IPv6Network $network
84
     *
85
     * @return bool
86
     */
87
    public function abuts(IPv6Network $network)
88
    {
89
        return
90
            $network->endPoint()->eq($this->network->startPoint()) ||
91
            $this->network->endPoint()->eq($network->startPoint())
92
        ;
93
    }
94
}
95