GeoJsonMapPageUi::getJavascript()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\GeoJsonPages;
6
7
use Html;
8
use Maps\Presentation\OutputFacade;
9
10
class GeoJsonMapPageUi {
11
12
	private $json;
13
14 4
	public static function forExistingPage( string $mapJson ): self {
15 4
		return new self( $mapJson );
16
	}
17
18 4
	private function __construct( ?string $json ) {
19 4
		$this->json = $json;
20 4
	}
21
22 4
	public function addToOutput( OutputFacade $output ) {
23 4
		$output->addHTML( $this->getJavascript() . $this->getHtml() );
24 4
		$output->addModules( 'ext.maps.geojson.page' );
25 4
	}
26
27 4
	private function getJavascript(): string {
28 4
		return Html::element(
29 4
			'script',
30 4
			[],
31 4
			$this->getJsonJs()
32
		);
33
	}
34
35 4
	private function getJsonJs(): string {
36
		return 'var GeoJson ='
37 4
			. $this->json
38 4
			. ';';
39
	}
40
41 4
	private function getHtml(): string {
42 4
		return $this->wrapHtmlInThumbDivs(
43 4
			Html::rawElement(
44 4
				'div',
45
				[
46 4
					'id' => 'GeoJsonMap',
47
					'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;',
48
					'class' => 'maps-map maps-leaflet maps-geojson-editor'
49
				],
50 4
				Html::element(
51 4
					'div',
52
					[
53 4
						'class' => 'maps-loading-message'
54
					],
55 4
					wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
56
				)
57
			)
58
		);
59
	}
60
61 4
	private function wrapHtmlInThumbDivs( string $html ): string {
62 4
		return Html::rawElement(
63 4
			'div',
64
			[
65 4
				'class' => 'thumb'
66
			],
67 4
			Html::rawElement(
68 4
				'div',
69
				[
70 4
					'class' => 'thumbinner'
71
				],
72
				$html
73
			)
74
		);
75
	}
76
77
}
78