BasicNumberUnlocalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unlocalizeNumber() 0 3 1
A getNumberRegex() 0 3 1
A getUnitRegex() 0 4 1
1
<?php
2
3
namespace ValueParsers;
4
5
/**
6
 * @see \ValueFormatters\BasicNumberLocalizer
7
 *
8
 * @since 0.3
9
 *
10
 * @license GPL-2.0-or-later
11
 * @author Daniel Kinzler
12
 */
13
class BasicNumberUnlocalizer implements NumberUnlocalizer {
14
15
	/**
16
	 * @see NumberUnlocalizer::unlocalizeNumber
17
	 *
18
	 * @param string $number string to process
19
	 *
20
	 * @return string unlocalized number, in a form suitable for floatval resp. intval.
21
	 */
22 19
	public function unlocalizeNumber( $number ) {
23 19
		return preg_replace( '/[^-+\d.EX]+/i', '', $number );
24
	}
25
26
	/**
27
	 * @see NumberUnlocalizer::getNumberRegex
28
	 *
29
	 * This implementation returns an expression that will match a number
30
	 * in english notation, including scientific notation.
31
	 *
32
	 * @param string $delimiter The regex delimiter, used for escaping.
33
	 *
34
	 * @return string regular expression
35
	 */
36 33
	public function getNumberRegex( $delimiter = '/' ) {
37 33
		return '(?:[-+]\s*)?(?:[\d,]+\.\d*|\.?\d+)(?:[eE][-+]?\d+)?';
38
	}
39
40
	/**
41
	 * @see NumberUnlocalizer::getUnitRegex
42
	 *
43
	 * @param string $delimiter Unused.
44
	 *
45
	 * @return string An empty string.
46
	 */
47 10
	public function getUnitRegex( $delimiter = '/' ) {
48
		// TODO: Discuss and specify what QuantityParser should accept.
49 10
		return '';
50
	}
51
52
}
53