Completed
Pull Request — master (#104)
by no
21:17 queued 11:18
created

GlobeCoordinateFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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
	public function __construct( FormatterOptions $options = null ) {
32
		$this->formatter = new LatLongFormatter( $options );
33 51
	}
34 51
35
	/**
36
	 * @see ValueFormatter::format
37
	 *
38 51
	 * @param GlobeCoordinateValue $value
39
	 *
40 51
	 * @return string Plain text
41
	 * @throws InvalidArgumentException
42
	 */
43
	public function format( $value ) {
44
		if ( !( $value instanceof GlobeCoordinateValue ) ) {
45
			throw new InvalidArgumentException( 'Data value type mismatch. Expected a GlobeCoordinateValue.' );
46
		}
47
48
		return $this->formatter->formatLatLongValue( $value->getLatLong(), $value->getPrecision() );
49
	}
50
51
}
52