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

MapHtmlBuilder::getMapHTML()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 18
cts 18
cp 1
rs 9.44
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Map;
6
7
use FormatJson;
8
use Html;
9
10
class MapHtmlBuilder {
11
12 29
	public function getMapHTML( array $json, string $mapId, string $serviceName ): string {
13 29
		if ( is_int( $json['height'] ) ) {
14 29
			$json['height'] = (string)$json['height'] . 'px';
15
		}
16
17 29
		if ( is_int( $json['width'] ) ) {
18 1
			$json['width'] = (string)$json['width'] . 'px';
19
		}
20
21 29
		return Html::rawElement(
22 29
			'div',
23
			[
24 29
				'id' => $mapId,
25 29
				'style' => "width: {$json['width']}; height: {$json['height']}; background-color: #eeeeee; overflow: hidden;",
26 29
				'class' => 'maps-map maps-' . $serviceName
27
			],
28 29
			Html::element(
29 29
				'div',
30
				[
31 29
					'class' => 'maps-loading-message'
32
				],
33 29
				wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
34
			)
35 29
			. Html::element(
36 29
				'div',
37 29
				[ 'style' => 'display:none', 'class' => 'mapdata' ],
38 29
				FormatJson::encode( $json )
39
			)
40
		);
41
	}
42
43
}
44