Passed
Push — globeOptions ( 78b216 )
by no
03:06
created

GlobeCoordinateFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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