Completed
Push — master ( ceb9a8...527314 )
by ARCANEDEV
14s
created

Elevation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 106
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A value() 0 4 1
A location() 0 4 1
A resolution() 0 4 1
A toArray() 0 8 1
1
<?php namespace Arcanedev\GeoLocation\Google\Elevation\Entities;
2
3
use Arcanedev\GeoLocation\Entities\Coordinates\Position;
4
use Arcanedev\GeoLocation\Traits\CanBeJsonable;
5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Contracts\Support\Jsonable;
7
use Illuminate\Support\Arr;
8
use JsonSerializable;
9
10
/**
11
 * Class     Elevation
12
 *
13
 * @package  Arcanedev\GeoLocation\Google\Elevation\Entities
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class Elevation implements Arrayable, Jsonable, JsonSerializable
17
{
18
    /* -----------------------------------------------------------------
19
     |  Traits
20
     | -----------------------------------------------------------------
21
     */
22
23
    use CanBeJsonable;
24
25
    /* -----------------------------------------------------------------
26
     |  Properties
27
     | -----------------------------------------------------------------
28
     */
29
30
    /**
31
     * The elevation value.
32
     *
33
     * @var float
34
     */
35
    protected $value;
36
37
    /**
38
     * The location.
39
     *
40
     * @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
41
     */
42
    protected $location;
43
44
    /**
45
     * The resolution.
46
     *
47
     * @var float
48
     */
49
    protected $resolution;
50
51
    /* -----------------------------------------------------------------
52
     |  Constructor
53
     | -----------------------------------------------------------------
54
     */
55
56
    /**
57
     * Elevation constructor.
58
     *
59
     * @param  array  $data
60
     */
61 9
    public function __construct(array $data)
62
    {
63 9
        $this->value      = Arr::get($data, 'elevation', 0.0);
64 9
        $this->location   = Position::createFromArray(Arr::get($data, 'location', []));
65 9
        $this->resolution = Arr::get($data, 'resolution', 0.0);
66 9
    }
67
68
    /* -----------------------------------------------------------------
69
     |  Getters & Setters
70
     | -----------------------------------------------------------------
71
     */
72
73
    /**
74
     * Get the elevation value.
75
     *
76
     * @return float
77
     */
78 9
    public function value()
79
    {
80 9
        return $this->value;
81
    }
82
83
    /**
84
     * Get the location.
85
     *
86
     * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
87
     */
88 9
    public function location()
89
    {
90 9
        return $this->location;
91
    }
92
93
    /**
94
     * Get the resolution.
95
     *
96
     * @return float
97
     */
98 9
    public function resolution()
99
    {
100 9
        return $this->resolution;
101
    }
102
103
    /* -----------------------------------------------------------------
104
     |  Main Methods
105
     | -----------------------------------------------------------------
106
     */
107
108
    /**
109
     * Get the instance as an array.
110
     *
111
     * @return array
112
     */
113 3
    public function toArray()
114
    {
115
        return [
116 3
            'elevation'  => $this->value(),
117 3
            'location'   => $this->location()->toArray(),
118 3
            'resolution' => $this->resolution(),
119 1
        ];
120
    }
121
}
122