Range::assertTheseAreIntegers()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 16
Ratio 80 %

Code Coverage

Tests 4
CRAP Score 15.5468

Importance

Changes 0
Metric Value
dl 16
loc 20
c 0
b 0
f 0
ccs 4
cts 16
cp 0.25
rs 8.8571
cc 5
eloc 11
nc 3
nop 2
crap 15.5468
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