Passed
Push — nullBounds ( b3e7e4...f3529c )
by no
03:35
created

QuantityHtmlFormatter::formatNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace ValueFormatters;
4
5
use DataValues\QuantityValue;
6
7
/**
8
 * HTML formatter for quantity values.
9
 *
10
 * @since 0.6
11
 *
12
 * @license GPL-2.0+
13
 * @author Thiemo Mättig
14
 */
15
class QuantityHtmlFormatter extends QuantityFormatter {
16
17
	/**
18
	 * @see QuantityFormatter::formatNumber
19
	 *
20
	 * @param QuantityValue $quantity
21
	 *
22
	 * @return string HTML
23
	 */
24
	protected function formatNumber( QuantityValue $quantity ) {
25
		$formatted = parent::formatNumber( $quantity );
26
27
		return htmlspecialchars( $formatted );
28
	}
29
30
	/**
31
	 * @see QuantityFormatter::formatUnit
32
	 *
33
	 * @param string $unit URI
34
	 *
35
	 * @return string|null HTML
36
	 */
37
	protected function formatUnit( $unit ) {
38
		$formatted = parent::formatUnit( $unit );
39
40
		if ( $formatted === null ) {
41
			return null;
42
		}
43
44
		return '<span class="wb-unit">' . htmlspecialchars( $formatted ) . '</span>';
45
	}
46
47
}
48