Completed
Push — cleanz ( f1882e...25c139 )
by Jeroen De
27:32 queued 25:40
created

Circle   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 48
ccs 23
cts 24
cp 0.9583
rs 10
c 0
b 0
f 0

6 Methods

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