Passed
Push — master ( 152a70...0c8393 )
by Jose
03:00
created

TerrainGenerator::validateOptionalInteger()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
1
<?php
2
3
namespace JMGQ\AStar\Benchmark;
4
5
use JMGQ\AStar\Example\Terrain\TerrainCost;
6
7
class TerrainGenerator
8
{
9 7
    public function generate(int $rows, int $columns, ?int $seed = null): TerrainCost
10
    {
11 7
        $this->validatePositiveInteger($rows);
12 5
        $this->validatePositiveInteger($columns);
13
14 3
        mt_srand($seed);
0 ignored issues
show
Bug introduced by
It seems like $seed can also be of type null; however, parameter $seed of mt_srand() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

14
        mt_srand(/** @scrutinizer ignore-type */ $seed);
Loading history...
15
16 3
        $terrainCost = [];
17
18 3
        foreach (range(0, $rows - 1) as $row) {
19 3
            foreach (range(0, $columns - 1) as $column) {
20 3
                $terrainCost[$row][$column] = mt_rand(1, 10);
21
            }
22
        }
23
24 3
        return new TerrainCost($terrainCost);
25
    }
26
27 7
    private function validatePositiveInteger(int $number): void
28
    {
29 7
        if ($number < 1) {
30 4
            throw new \InvalidArgumentException("Invalid positive integer: $number");
31
        }
32 5
    }
33
}
34