Completed
Push — wip ( 4d3464 )
by Jeroen De
03:36
created

MapOutputBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 38
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildOutput() 0 16 1
A getParameterDefinitions() 0 3 1
A buildMapHtml() 0 5 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Cargo;
6
7
use Maps\MappingService;
8
use Maps\MappingServices;
9
use Maps\Presentation\MapHtmlBuilder;
10
use ParamProcessor\ParamDefinitionFactory;
11
use ParamProcessor\Processor;
12
13
class MapOutputBuilder {
14
15
	private $services;
16
	private $paramDefinitionFactory;
17
18
	public function __construct( MappingServices $services, ParamDefinitionFactory $paramDefinitionFactory ) {
19
		$this->services = $services;
20
		$this->paramDefinitionFactory = $paramDefinitionFactory;
21
	}
22
23
	public function buildOutput( array $parameters ): MapOutput {
24
		$processor = Processor::newDefault();
25
26
		$service = $this->services->getDefaultService();
27
28
		$processor->setParameters( $parameters );
29
		$processor->setParameterDefinitions( $this->getParameterDefinitions( $service ) );
30
31
		$mapParams = $service->processingResultToMapParams( $processor->processParameters() );
32
33
		return new MapOutput(
34
			$this->buildMapHtml( $mapParams, $service->getName() ),
35
			$service->getResourceModules( $mapParams ),
36
			$service->getDependencyHtml( $mapParams )
37
		);
38
	}
39
40
	private function getParameterDefinitions( MappingService $service ): array {
41
		return $this->paramDefinitionFactory->newDefinitionsFromArrays( $service->getParameterInfo() ) ;
42
	}
43
44
	private function buildMapHtml( array $mapParams, string $serviceName ): string {
45
		$htmlBuilder = new MapHtmlBuilder();
46
47
		return $htmlBuilder->getMapHTML( $mapParams, 'cargo_map', $serviceName ); // TODO
48
	}
49
50
}
51