Passed
Branch benchmark (b81757)
by Jose
02:27
created

Result::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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 View Code Duplication
    private function filterSize($size)
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...
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));
44
        }
45
46 13
        return $naturalNumber;
47
    }
48
49 13 View Code Duplication
    private function filterDuration($duration)
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...
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));
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