Completed
Push — cargo ( bb6ae5...2d509c )
by Jeroen De
03:25
created

StructuredPopup   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 40
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getHtml() 0 6 3
A getPropertyValueList() 0 9 2
A stripTags() 0 3 1
A bold() 0 3 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Map;
6
7
class StructuredPopup {
8
9
	private $titleHtml;
10
	private $propertyValues;
11
12
	/**
13
	 * @param string $titleHtml
14
	 * @param string[] $propertyValues
15
	 */
16
	public function __construct( string $titleHtml, array $propertyValues ) {
17
		$this->titleHtml = $titleHtml;
18
		$this->propertyValues = $propertyValues;
19
	}
20
21
	public function getHtml(): string {
22
		$valueList = $this->getPropertyValueList();
23
		$separator = $this->titleHtml === '' || $valueList === '' ? '' : '<br>';
24
25
		return '<h3>' . $this->titleHtml . '</h3>' . $separator . $valueList;
26
	}
27
28
	private function getPropertyValueList(): string {
29
		$lines = [];
30
31
		foreach ( $this->propertyValues as $name => $value ) {
32
			$lines[] = $this->bold( $this->stripTags( $name ) ) . ': ' . $this->stripTags( $value );
33
		}
34
35
		return implode( '<br>', $lines );
36
	}
37
38
	private function stripTags( string $html ): string {
39
		return strip_tags( $html, '<a><img>' );
40
	}
41
42
	private function bold( string $html ): string {
43
		return '<strong>' . $html . '</strong>';
44
	}
45
46
}
47