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

StructuredPopup::bold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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