Completed
Push — cargo ( d35b5e...08c93e )
by Jeroen De
05:35
created

PopupContent::shouldDisplayValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Map\CargoFormat;
6
7
class PopupContent {
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( $name ) . ': ' . $value;
33
		}
34
35
		return implode( '<br>', $lines );
36
	}
37
38
	private function bold( string $html ): string {
39
		return '<strong>' . $html . '</strong>';
40
	}
41
42
	private function shouldDisplayValue( string $name, array $coordinateFields ): bool {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
43
		$hiddenFields = [];
44
45
		foreach ( $coordinateFields as $field ) {
46
			$hiddenFields[] = $field;
47
			$hiddenFields[] = $field . '  lat';
48
			$hiddenFields[] = $field . '  lon';
49
		}
50
51
		return !in_array( $name, $hiddenFields );
52
	}
53
54
}
55