QuantityHtmlFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A formatNumber() 0 5 1
A formatUnit() 0 9 2
1
<?php
2
3
namespace ValueFormatters;
4
5
use DataValues\UnboundedQuantityValue;
6
7
/**
8
 * HTML formatter for quantity values.
9
 *
10
 * @since 0.6
11
 *
12
 * @license GPL-2.0-or-later
13
 * @author Thiemo Kreuz
14
 */
15
class QuantityHtmlFormatter extends QuantityFormatter {
16
17
	/**
18
	 * @see QuantityFormatter::formatNumber
19
	 *
20
	 * @param UnboundedQuantityValue $quantity
21
	 *
22
	 * @return string HTML
23
	 */
24 13
	protected function formatNumber( UnboundedQuantityValue $quantity ) {
25 13
		$formatted = parent::formatNumber( $quantity );
26
27 13
		return htmlspecialchars( $formatted );
28
	}
29
30
	/**
31
	 * @see QuantityFormatter::formatUnit
32
	 *
33
	 * @param string $unit URI
34
	 *
35
	 * @return string|null HTML
36
	 */
37 13
	protected function formatUnit( $unit ) {
38 13
		$formatted = parent::formatUnit( $unit );
39
40 13
		if ( $formatted === null ) {
41 8
			return null;
42
		}
43
44 5
		return '<span class="wb-unit">' . htmlspecialchars( $formatted ) . '</span>';
45
	}
46
47
}
48