QuantityHtmlFormatter::formatNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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