Passed
Push — master ( 5a00cf...0692f7 )
by Petr
02:06
created

MapTransformer::convertToString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Vehsamrak\Terraformator\Service;
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 MapTransformer
13
{
14
15 3
    public function convertToString(Map $map): string
16
    {
17 3
        $stringMap = '';
18
19
        /** @var Location $location */
20 3
        foreach ($map->toArray() as $location) {
21 2
            $biom = $location->getBiom();
22 2
            $stringMap .= $this->getSymbolByBiom($biom);
23
        }
24
25 3
        return $stringMap;
26
    }
27
28 2
    private function getSymbolByBiom(Biom $biom): string
29
    {
30
        $biomSymbolMatrix = [
31 2
            Biom::FOREST => '^',
32
            Biom::FIELD  => '_',
33
        ];
34
35 2
        return $biomSymbolMatrix[$biom->getValue()];
36
    }
37
}
38