IPv4IntervalPoint::value()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\IPv4;
12
13
use GpsLab\Component\Interval\Exception\InvalidPointTypeException;
14
use GpsLab\Component\Interval\BaseIntervalPoint;
15
16
class IPv4IntervalPoint extends BaseIntervalPoint
17
{
18
    /**
19
     * @var string
20
     */
21
    const IPV4_SEG = '(25[0-5]|(2[0-4]|1?[0-9])?[0-9])';
22
23
    /**
24
     * @var string
25
     */
26
    const IPV4_ADDR = '('.self::IPV4_SEG.'\.){3,3}'.self::IPV4_SEG;
27
28
    /**
29
     * @var string
30
     */
31
    private $ip;
32
33
    /**
34
     * @var int
35
     */
36
    private $long;
37
38
    /**
39
     * @param string $ip
40
     */
41 33 View Code Duplication
    public function __construct($ip)
0 ignored issues
show
Duplication introduced by
This method 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...
42
    {
43 33
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
44
            throw InvalidPointTypeException::point('IPv4', $ip);
45
        }
46
47 33
        $this->ip = $ip;
48 33
        $this->long = ip2long($ip);
49 33
    }
50
51
    /**
52
     * @return int
53
     */
54 33
    public function value()
55
    {
56 33
        return $this->long;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 18
    public function __toString()
63
    {
64 18
        return $this->ip;
65
    }
66
}
67