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

Circle::setCircleRadius()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
 * @licence GNU GPL v2+
14
 * @author Kim Eik < [email protected] >
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class Circle extends \Maps\LegacyModel\BaseFillableElement {
18
19
	private $circleCentre;
20
	private $circleRadius;
21
22
	public function __construct( LatLongValue $circleCentre, float $circleRadius ) {
23
		if ( !is_float( $circleRadius ) && !is_int( $circleRadius ) ) {
24
			throw new InvalidArgumentException( '$circleRadius must be a float or int' );
25
		}
26
27
		if ( $circleRadius <= 0 ) {
28
			throw new InvalidArgumentException( '$circleRadius must be greater than zero' );
29
		}
30
31
		$this->setCircleCentre( $circleCentre );
32
		$this->setCircleRadius( $circleRadius );
33
	}
34
35
	public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
36
		return array_merge(
37
			parent::getJSONObject( $defText, $defTitle ),
38
			[
39
				'centre' => [
40
					'lon' => $this->getCircleCentre()->getLongitude(),
41
					'lat' => $this->getCircleCentre()->getLatitude()
42
				],
43
				'radius' => intval( $this->getCircleRadius() ),
44
			]
45
		);
46
	}
47
48
	public function getCircleCentre(): LatLongValue {
49
		return $this->circleCentre;
50
	}
51
52
	public function setCircleCentre( LatLongValue $circleCentre ) {
53
		$this->circleCentre = $circleCentre;
54
	}
55
56
	public function getCircleRadius(): float {
57
		return $this->circleRadius;
58
	}
59
60
	public function setCircleRadius( float $circleRadius ) {
61
		$this->circleRadius = $circleRadius;
62
	}
63
64
}
65