Position::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php namespace Cornford\Pokenotifier\Models;
2
3
use Cornford\Pokenotifier\Contracts\PositioningInterface;
4
5
class Position implements PositioningInterface {
6
7
	/**
8
	 * Latitude.
9
	 *
10
	 * @var float
11
	 */
12
	protected $latitude = [];
13
14
	/**
15
	 * Longitude.
16
	 *
17
	 * @var float
18
	 */
19
	protected $longitude = [];
20
21
	/**
22
	 * Public constructor.
23
	 *
24
	 * @param float $latitude
25
	 * @param float $longitude
26
	 */
27
	public function __construct($latitude, $longitude)
28
	{
29
		$this->latitude = $latitude;
30
		$this->longitude = $longitude;
31
	}
32
33
	/**
34
	 * Get longitude.
35
	 *
36
	 * @return float
37
	 */
38
	public function getLongitude()
39
	{
40
		return $this->longitude;
41
	}
42
43
	/**
44
	 * Set longitude.
45
	 *
46
	 * @param float $longitude
47
	 *
48
	 * @return void
49
	 */
50
	public function setLongitude($longitude)
51
	{
52
		$this->longitude = $longitude;
53
	}
54
55
	/**
56
	 * Get latitude.
57
	 *
58
	 * @return float
59
	 */
60
	public function getLatitude()
61
	{
62
		return $this->latitude;
63
	}
64
65
	/**
66
	 * Set latitude.
67
	 *
68
	 * @param float $latitude
69
	 *
70
	 * @return float
71
	 */
72
	public function setLatitude($latitude)
73
	{
74
		$this->latitude = $latitude;
75
	}
76
77
	/**
78
	 * Calculate distance in meters between the current and another position.
79
	 *
80
	 * @param Position $position
81
	 *
82
	 * @return float
83
	 */
84
	public function calculateDistance(Position $position)
85
	{
86
		$theta = $this->getLongitude() - $position->getLongitude();
87
		$dist = rad2deg(acos(sin(deg2rad($this->getLatitude())) * sin(deg2rad($position->getLatitude())) + cos(deg2rad($this->getLatitude())) * cos(deg2rad($position->getLatitude())) * cos(deg2rad($theta))));
88
		$miles = $dist * 60 * 1.1515;
89
90
		return round($miles * 1.609344 * 1000);
91
	}
92
93
}
94