IPv4IntervalPoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 9
loc 51
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 2
A value() 0 4 1
A __toString() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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