Completed
Push — master ( f04bbc...eab9d5 )
by Jeroen De
07:09
created

DistanceParser::stringParse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Maps;
4
5
use ValueParsers\ParseException;
6
use ValueParsers\StringValueParser;
7
8
/**
9
 * ValueParser that parses the string representation of a distance.
10
 *
11
 * @since 3.0
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class DistanceParser extends StringValueParser {
17
18
	/**
19
	 * @see StringValueParser::stringParse
20
	 *
21
	 * @since 3.0
22
	 *
23
	 * @param string $value
24
	 *
25
	 * @return float
26
	 * @throws ParseException
27
	 */
28 18
	public function stringParse( $value ) {
29 18
		$distance = \MapsDistanceParser::parseDistance( $value );
30
31 18
		if ( $distance === false ) {
32 10
			throw new ParseException( 'Not a distance' );
33
		}
34
35 8
		return $distance;
36
	}
37
38
}
39