Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

Rectangle   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 65
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getJSONObject() 0 15 1
A getRectangleNorthEast() 0 3 1
A setRectangleNorthEast() 0 3 1
A getRectangleSouthWest() 0 3 1
A setRectangleSouthWest() 0 3 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\LegacyModel;
6
7
use DataValues\Geo\Values\LatLongValue;
8
use InvalidArgumentException;
9
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 Rectangle extends \Maps\LegacyModel\BaseFillableElement {
19
20
	/**
21
	 * @since 3.0
22
	 * @var LatLongValue
23
	 */
24
	protected $rectangleNorthEast;
25
26
	/**
27
	 * @since 3.0
28
	 * @var LatLongValue
29
	 */
30
	protected $rectangleSouthWest;
31
32
	/**
33
	 * @since 3.0
34
	 *
35
	 * @param LatLongValue $rectangleNorthEast
36
	 * @param LatLongValue $rectangleSouthWest
37
	 *
38
	 * @throws InvalidArgumentException
39
	 */
40
	public function __construct( LatLongValue $rectangleNorthEast, LatLongValue $rectangleSouthWest ) {
41
		if ( $rectangleNorthEast->equals( $rectangleSouthWest ) ) {
42
			throw new InvalidArgumentException( '$rectangleNorthEast cannot be equal to $rectangleSouthWest' );
43
		}
44
45
		// TODO: validate bounds are correct, if not, flip
46
		$this->setRectangleNorthEast( $rectangleNorthEast );
47
		$this->setRectangleSouthWest( $rectangleSouthWest );
48
	}
49
50
	public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
51
		$parentArray = parent::getJSONObject( $defText, $defTitle );
52
		$array = [
53
			'ne' => [
54
				'lon' => $this->getRectangleNorthEast()->getLongitude(),
55
				'lat' => $this->getRectangleNorthEast()->getLatitude()
56
			],
57
			'sw' => [
58
				'lon' => $this->getRectangleSouthWest()->getLongitude(),
59
				'lat' => $this->getRectangleSouthWest()->getLatitude()
60
			],
61
		];
62
63
		return array_merge( $parentArray, $array );
64
	}
65
66
	public function getRectangleNorthEast(): LatLongValue {
67
		return $this->rectangleNorthEast;
68
	}
69
70
	public function setRectangleNorthEast( LatLongValue $rectangleNorthEast ) {
71
		$this->rectangleNorthEast = $rectangleNorthEast;
72
	}
73
74
	public function getRectangleSouthWest(): LatLongValue {
75
		return $this->rectangleSouthWest;
76
	}
77
78
	public function setRectangleSouthWest( LatLongValue $rectangleSouthWest ) {
79
		$this->rectangleSouthWest = $rectangleSouthWest;
80
	}
81
82
}
83