Coordinate::__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
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
<?php
2
namespace Nubs\Coordinator;
3
4
class Coordinate
5
{
6
    /**
7
     * Latitude in radians
8
     *
9
     * @var float
10
     */
11
    private $_latitude;
12
13
    /**
14
     * Longitude in radians
15
     *
16
     * @var float
17
     */
18
    private $_longitude;
19
20
    /**
21
     * Initialize a coordinate.
22
     *
23
     * @param float $latitude The latitude in radians
24
     * @param float $longitude The longitude in radians
25
     */
26
    public function __construct($latitude, $longitude)
27
    {
28
        $this->_latitude = $latitude;
29
        $this->_longitude = $longitude;
30
    }
31
32
    /**
33
     * Convert the latitude to radians.
34
     *
35
     * @return float The latitude in radians.
36
     */
37
    public function latitudeInRadians()
38
    {
39
        return $this->_latitude;
40
    }
41
42
    /**
43
     * Convert the longitude to radians.
44
     *
45
     * @return float The longitude in radians.
46
     */
47
    public function longitudeInRadians()
48
    {
49
        return $this->_longitude;
50
    }
51
52
    /**
53
     * Convert the latitude to degrees.
54
     *
55
     * @return float The latitude in degrees.
56
     */
57
    public function latitudeInDegrees()
58
    {
59
        return rad2deg($this->_latitude);
60
    }
61
62
    /**
63
     * Convert the longitude to degrees.
64
     *
65
     * @return float The longitude in degrees.
66
     */
67
    public function longitudeInDegrees()
68
    {
69
        return rad2deg($this->_longitude);
70
    }
71
72
    /**
73
     * Return the latitude and longitude in degrees as a string.
74
     *
75
     * @return string A string representation of the coordinate.
76
     */
77
    public function __toString()
78
    {
79
        return "{$this->latitudeInDegrees()}, {$this->longitudeInDegrees()}";
80
    }
81
}
82