Passed
Push — master ( 4d5ddd...71276c )
by Petr
02:06
created

BiomQualifier::getRandomBiom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Vehsamrak\Terraformator\LocationGenerator;
4
5
use Vehsamrak\Terraformator\Entity\Location;
6
use Vehsamrak\Terraformator\Entity\Map;
7
use Vehsamrak\Terraformator\Enum\Biom;
8
9
/**
10
 * @author Vehsamrak
11
 */
12
class BiomQualifier
13
{
14
15 3
    public function qualifyBiom(Map $map): Biom
16
    {
17 3
        $firstLocationInMap = $map->first();
18
19 3
        if ($firstLocationInMap) {
20 2
            $firstBiom = $firstLocationInMap->getBiom();
21 2
            $locationsAreSame = true;
22
23
            /** @var Location $location */
24 2
            foreach ($map->toArray() as $location) {
25 2
                if (!$location->getBiom()->equals($firstBiom)) {
26 2
                    $locationsAreSame = false;
27
                }
28
            }
29
30 2
            if ($map->count() == 8 && $locationsAreSame) {
31 2
                return $firstBiom;
32
            }
33
        }
34
35 1
        return $this->getRandomBiom();
36
    }
37
38 1
    private function getRandomBiom(): Biom
39
    {
40 1
        $allBioms = Biom::values();
41 1
        $randomBiom = $allBioms[array_rand($allBioms)];
42
43 1
        return $randomBiom;
44
    }
45
}
46