Passed
Branch benchmark (b81757)
by Jose
10:16
created

TerrainGenerator::validateOptionalInteger()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "TerrainGenerator.php" doesn't match the expected filename "terraingenerator.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace JMGQ\AStar\Benchmark;
4
5
use JMGQ\AStar\Example\Terrain\TerrainCost;
6
7
class TerrainGenerator
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
8
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class TerrainGenerator
Loading history...
9
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
10
     * @param int $rows
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
11
     * @param int $columns
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
12
     * @param int | null $seed
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
13
     * @return TerrainCost
14
     */
15
    public function generate($rows, $columns, $seed = null)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Type hint "int" missing for $rows
Loading history...
Coding Style introduced by
Type hint "int" missing for $columns
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
16
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
17
        $this->validatePositiveInteger($rows);
18
        $this->validatePositiveInteger($columns);
19
        $this->validateOptionalInteger($seed);
20
21
        mt_srand($seed);
22
23
        $terrainCost = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
24
25
        foreach (range(0, $rows - 1) as $row) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
26
            foreach (range(0, $columns - 1) as $column) {
0 ignored issues
show
Coding Style introduced by
Arithmetic operation must be bracketed
Loading history...
27
                $terrainCost[$row][$column] = mt_rand(1, 10);
28
            }
29
        }
30
31
        return new TerrainCost($terrainCost);
32
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end generate()
Loading history...
33
34
    private function validatePositiveInteger($number)
0 ignored issues
show
Coding Style introduced by
Private method name "TerrainGenerator::validatePositiveInteger" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
35
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
36
        $positiveInteger = filter_var($number, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
37
38
        if ($positiveInteger === false) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
39
            throw new \InvalidArgumentException('Invalid positive integer: ' . print_r($number, true));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
40
        }
41
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end validatePositiveInteger()
Loading history...
42
43 View Code Duplication
    private function validateOptionalInteger($number)
0 ignored issues
show
Coding Style introduced by
Private method name "TerrainGenerator::validateOptionalInteger" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
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...
44
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
45
        $integer = filter_var($number, FILTER_VALIDATE_INT);
46
47
        if ($integer === false && $number !== null) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
48
            throw new \InvalidArgumentException('Invalid integer: ' . print_r($number, true));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
49
        }
50
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end validateOptionalInteger()
Loading history...
51
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
52