Completed
Push — cargo ( 2d509c...8058d2 )
by Jeroen De
03:32
created

StructuredPopup   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 40
ccs 17
cts 17
cp 1
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 6
	public function __construct( string $titleHtml, array $propertyValues ) {
17 6
		$this->titleHtml = $titleHtml;
18 6
		$this->propertyValues = $propertyValues;
19 6
	}
20
21 6
	public function getHtml(): string {
22 6
		$valueList = $this->getPropertyValueList();
23 6
		$separator = $this->titleHtml === '' || $valueList === '' ? '' : '<br>';
24
25 6
		return '<h3 style="padding-top: 0">' . $this->titleHtml . '</h3>' . $separator . $valueList;
26
	}
27
28 6
	private function getPropertyValueList(): string {
29 6
		$lines = [];
30
31 6
		foreach ( $this->propertyValues as $name => $value ) {
32 5
			$lines[] = $this->bold( $this->stripTags( $name ) ) . ': ' . $this->stripTags( $value );
33
		}
34
35 6
		return implode( '<br>', $lines );
36
	}
37
38 5
	private function stripTags( string $html ): string {
39 5
		return strip_tags( $html, '<a><img>' );
40
	}
41
42 5
	private function bold( string $html ): string {
43 5
		return '<strong>' . $html . '</strong>';
44
	}
45
46
}
47