Passed
Push — zeroRounding ( 491d2a...2f1015 )
by no
35:13 queued 21:46
created

GlobeCoordinateFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace DataValues\Geo\Formatters;
4
5
use DataValues\Geo\Values\GlobeCoordinateValue;
6
use InvalidArgumentException;
7
use ValueFormatters\FormatterOptions;
8
use ValueFormatters\ValueFormatter;
9
10
/**
11
 * Geographical coordinates formatter.
12
 * Formats GlobeCoordinateValue objects.
13
 *
14
 * Formatting of latitude and longitude is done via LatLongFormatter.
15
 *
16
 * For now this is a trivial implementation that only forwards to LatLongFormatter.
17
 * TODO: add formatting of globe and precision
18
 *
19
 * @since 0.1
20
 *
21
 * @license GPL-2.0+
22
 * @author Jeroen De Dauw < [email protected] >
23
 */
24
class GlobeCoordinateFormatter implements ValueFormatter {
25
26
	/**
27
	 * @var LatLongFormatter
28
	 */
29
	private $formatter;
30
31 51
	public function __construct( FormatterOptions $options = null ) {
32 51
		$this->formatter = new LatLongFormatter( $options );
33 51
	}
34
35
	/**
36
	 * @see ValueFormatter::format
37
	 *
38
	 * @param GlobeCoordinateValue $value
39
	 *
40
	 * @return string Plain text
41
	 * @throws InvalidArgumentException
42
	 */
43 51
	public function format( $value ) {
44 51
		if ( !( $value instanceof GlobeCoordinateValue ) ) {
45
			throw new InvalidArgumentException( 'Data value type mismatch. Expected a GlobeCoordinateValue.' );
46
		}
47
48 51
		return $this->formatter->formatLatLongValue( $value->getLatLong(), $value->getPrecision() );
49
	}
50
51
}
52