Range   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 32 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 52%

Importance

Changes 0
Metric Value
dl 16
loc 50
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0
ccs 13
cts 25
cp 0.52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMin() 0 4 1
A getMax() 0 4 1
B assertTheseAreIntegers() 16 20 5

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
namespace HansOtt\RangeRegex;
4
5
use InvalidArgumentException;
6
7
final class Range
8
{
9
    private $min;
10
11
    private $max;
12
13
    /**
14
     * Range constructor.
15
     *
16
     * @param int $min
17
     * @param int $max
18
     */
19 8
    public function __construct($min, $max)
20
    {
21 8
        $this->assertTheseAreIntegers($min, $max);
22 8
        $this->min = $min;
23 8
        $this->max = $max;
24 8
    }
25
26 8
    public function getMin()
27
    {
28 8
        return $this->min;
29
    }
30
31 8
    public function getMax()
32
    {
33 8
        return $this->max;
34
    }
35
36 8
    private function assertTheseAreIntegers($min, $max)
37
    {
38 8 View Code Duplication
        if (is_int($min) === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
39
            throw new InvalidArgumentException(
40
                sprintf(
41
                    'Expected an integer as $min but instead got: %s',
42
                    is_object($min) ? get_class($min) : gettype($min)
43
                )
44
            );
45
        }
46
47 8 View Code Duplication
        if (is_int($max) === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
            throw new InvalidArgumentException(
49
                sprintf(
50
                    'Expected an integer as $max but instead got: %s',
51
                    is_object($max) ? get_class($max) : gettype($max)
52
                )
53
            );
54
        }
55 8
    }
56
}
57