Passed
Push — master ( 130a84...94bf46 )
by Jose
05:30 queued 02:40
created

Result::filterDuration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace JMGQ\AStar\Benchmark\Result;
4
5
class Result
6
{
7
    private $size;
8
    private $duration;
9
    private $hasSolution;
10
11
    /**
12
     * @param int $size
13
     * @param int $duration
14
     * @param bool $hasSolution
15
     */
16 19
    public function __construct($size, $duration, $hasSolution)
17
    {
18 19
        $this->size = $this->filterSize($size);
19 13
        $this->duration = $this->filterDuration($duration);
20 6
        $this->hasSolution = $this->filterHasSolution($hasSolution);
21 6
    }
22
23 4
    public function getSize()
24
    {
25 4
        return $this->size;
26
    }
27
28 4
    public function getDuration()
29
    {
30 4
        return $this->duration;
31
    }
32
33 5
    public function hasSolution()
34
    {
35 5
        return $this->hasSolution;
36
    }
37
38 19
    private function filterSize($size)
39
    {
40 19
        $naturalNumber = filter_var($size, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
41
42 19
        if ($naturalNumber === false) {
43 6
            throw new \InvalidArgumentException('Invalid size: ' . print_r($size, true));
0 ignored issues
show
Bug introduced by
Are you sure print_r($size, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
            throw new \InvalidArgumentException('Invalid size: ' . /** @scrutinizer ignore-type */ print_r($size, true));
Loading history...
44
        }
45
46 13
        return $naturalNumber;
47
    }
48
49 13
    private function filterDuration($duration)
50
    {
51 13
        $nonNegativeInteger = filter_var($duration, FILTER_VALIDATE_INT, array('options' => array('min_range' => 0)));
52
53 13
        if ($nonNegativeInteger === false) {
54 7
            throw new \InvalidArgumentException('Invalid duration: ' . print_r($duration, true));
0 ignored issues
show
Bug introduced by
Are you sure print_r($duration, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
            throw new \InvalidArgumentException('Invalid duration: ' . /** @scrutinizer ignore-type */ print_r($duration, true));
Loading history...
55
        }
56
57 6
        return $nonNegativeInteger;
58
    }
59
60 6
    private function filterHasSolution($hasSolution)
61
    {
62 6
        return filter_var($hasSolution, FILTER_VALIDATE_BOOLEAN);
63
    }
64
}
65