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

MapDataSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 28
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toJson() 0 10 2
A getLocationJson() 0 13 1
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