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

Result   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 20
loc 60
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSize() 0 4 1
A getDuration() 0 4 1
A hasSolution() 0 4 1
A filterSize() 10 10 2
A filterDuration() 10 10 2
A filterHasSolution() 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
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