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

GlobeCoordinateFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 28
ccs 6
cts 7
cp 0.8571
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A format() 0 7 2
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