Completed
Push — master ( 4d0076...81538e )
by Jeroen De
26s queued 11s
created

MapDataSerializer::toJson()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Map;
6
7
class MapDataSerializer {
8
9 29
	public function toJson( MapData $mapData ): array {
10 29
		$json = $mapData->getParameters();
11
12 29
		$json['locations'] = array_merge(
13 29
			array_key_exists( 'locations', $json ) ? $json['locations'] : [],
14 29
			$this->getLocationJson( $mapData )
15
		);
16
17 29
		return $json;
18
	}
19
20 29
	private function getLocationJson( MapData $mapData ): array {
21 29
		return array_map(
22 29
			function( Marker $marker ) {
23
				return [
24
					'lat' => $marker->getCoordinates()->getLatitude(),
25
					'lon' => $marker->getCoordinates()->getLongitude(),
26
					'icon' => $marker->getIconUrl(),
27
					'text' => $marker->getText(),
28
				];
29 29
			},
30 29
			$mapData->getMarkers()
31
		);
32
	}
33
34
}
35