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

BiomQualifier::qualifyBiom()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 8.6737
cc 6
eloc 11
nc 3
nop 1
crap 6
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