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

Rectangle::getRectangleSouthWest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maps\Elements;
4
5
use DataValues\Geo\Values\LatLongValue;
6
use InvalidArgumentException;
7
8
/**
9
 * @since 3.0
10
 *
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Kim Eik < [email protected] >
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class Rectangle extends \MapsBaseFillableElement {
17
18
	/**
19
	 * @since 3.0
20
	 * @var LatLongValue
21
	 */
22
	protected $rectangleNorthEast;
23
24
	/**
25
	 * @since 3.0
26
	 * @var LatLongValue
27
	 */
28
	protected $rectangleSouthWest;
29
30
	/**
31
	 * @since 3.0
32
	 *
33
	 * @param LatLongValue $rectangleNorthEast
34
	 * @param LatLongValue $rectangleSouthWest
35
	 *
36
	 * @throws InvalidArgumentException
37
	 */
38 3
	public function __construct( LatLongValue $rectangleNorthEast, LatLongValue $rectangleSouthWest ) {
39 3
		if ( $rectangleNorthEast->equals( $rectangleSouthWest ) ) {
40 1
			throw new InvalidArgumentException( '$rectangleNorthEast cannot be equal to $rectangleSouthWest' );
41
		}
42
43 2
		parent::__construct();
44
45
		// TODO: validate bounds are correct, if not, flip
46 2
		$this->setRectangleNorthEast( $rectangleNorthEast );
47 2
		$this->setRectangleSouthWest( $rectangleSouthWest );
48 2
	}
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 4
	public function getRectangleNorthEast(): LatLongValue {
67 4
		return $this->rectangleNorthEast;
68
	}
69
70 4
	public function setRectangleNorthEast( LatLongValue $rectangleNorthEast ) {
71 4
		$this->rectangleNorthEast = $rectangleNorthEast;
72 4
	}
73
74 4
	public function getRectangleSouthWest(): LatLongValue {
75 4
		return $this->rectangleSouthWest;
76
	}
77
78 4
	public function setRectangleSouthWest( LatLongValue $rectangleSouthWest ) {
79 4
		$this->rectangleSouthWest = $rectangleSouthWest;
80 4
	}
81
82
}
83