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

PopupContent   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 48
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 bold() 0 3 1
A shouldDisplayValue() 0 11 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