Completed
Push — nophpunit ( 9a5068 )
by Jeroen De
05:11
created

Line   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 54
ccs 9
cts 18
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLineCoordinates() 0 3 1
A __construct() 0 11 3
A getJSONObject() 0 15 2
1
<?php
2
3
namespace Maps\Elements;
4
5
use DataValues\Geo\Values\LatLongValue;
6
use InvalidArgumentException;
7
8
/**
9
 * Class representing a collection of LatLongValue objects forming a line.
10
 *
11
 * @since 3.0
12
 *
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Kim Eik < [email protected] >
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class Line extends \MapsBaseStrokableElement {
19
20
	/**
21
	 * @since 3.0
22
	 *
23
	 * @var LatLongValue[]
24
	 */
25
	protected $coordinates;
26
27
	/**
28
	 * @since 3.0
29
	 *
30
	 * @param LatLongValue[] $coordinates
31
	 *
32
	 * @throws InvalidArgumentException
33
	 */
34 6
	public function __construct( array $coordinates = [] ) {
35 6
		foreach ( $coordinates as $coordinate ) {
36 5
			if ( !( $coordinate instanceof LatLongValue ) ) {
37 5
				throw new InvalidArgumentException( 'Can only construct Line with LatLongValue objects' );
38
			}
39
		}
40
41 3
		$this->coordinates = $coordinates;
42
43 3
		parent::__construct();
44 3
	}
45
46
	/**
47
	 * @since 3.0
48
	 *
49
	 * @return LatLongValue[]
50
	 */
51 3
	public function getLineCoordinates() {
52 3
		return $this->coordinates;
53
	}
54
55
	public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
56
		$parentArray = parent::getJSONObject( $defText, $defTitle );
57
		$posArray = [];
58
59
		foreach ( $this->coordinates as $mapLocation ) {
60
			$posArray[] = [
61
				'lat' => $mapLocation->getLatitude(),
62
				'lon' => $mapLocation->getLongitude()
63
			];
64
		}
65
66
		$posArray = [ 'pos' => $posArray ];
67
68
		return array_merge( $parentArray, $posArray );
69
	}
70
71
}
72