1 | <?php |
||
12 | class MapTransformer |
||
13 | { |
||
14 | |||
15 | 6 | public function transformToString(Map $map, int $width = 0): string |
|
16 | { |
||
17 | 6 | $stringMap = ''; |
|
18 | |||
19 | /** @var Location $location */ |
||
20 | 6 | $mapLocations = $map->toArray(); |
|
21 | |||
22 | 6 | if (!count($mapLocations)) { |
|
23 | 1 | return $stringMap; |
|
24 | } |
||
25 | |||
26 | 5 | if ($width > 0) { |
|
27 | 3 | foreach (array_chunk($mapLocations, $width) as $locations) { |
|
28 | 3 | $stringMap .= $this->createStringSequence($locations); |
|
29 | 3 | $stringMap .= PHP_EOL; |
|
30 | } |
||
31 | } else { |
||
32 | 2 | $stringMap = $this->createStringSequence($mapLocations); |
|
33 | } |
||
34 | |||
35 | 5 | return $stringMap; |
|
36 | } |
||
37 | |||
38 | 5 | private function getSymbolByBiom(Biom $biom): string |
|
49 | |||
50 | 5 | private function createStringSequence(array $locations): string |
|
60 | } |
||
61 |