Completed
Push — master ( c2add9...d388c3 )
by ARCANEDEV
14s
created

Step::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php namespace Arcanedev\GeoLocation\Google\Directions\Entities;
2
3
use Arcanedev\GeoLocation\Entities\Measures\Distance;
4
use Arcanedev\GeoLocation\Entities\Measures\Duration;
5
use Arcanedev\GeoLocation\Entities\Coordinates\Position;
6
use Arcanedev\GeoLocation\Traits\CanBeJsonable;
7
use Illuminate\Contracts\Support\Arrayable;
8
use Illuminate\Contracts\Support\Jsonable;
9
use Illuminate\Support\Arr;
10
use JsonSerializable;
11
12
/**
13
 * Class     Step
14
 *
15
 * @package  Arcanedev\GeoLocation\Google\Directions\Entities
16
 * @author   ARCANEDEV <[email protected]>
17
 */
18
class Step implements Arrayable, Jsonable, JsonSerializable
19
{
20
    /* -----------------------------------------------------------------
21
     |  Traits
22
     | -----------------------------------------------------------------
23
     */
24
25
    use CanBeJsonable;
26
27
    /* -----------------------------------------------------------------
28
     |  Properties
29
     | -----------------------------------------------------------------
30
     */
31
32
    /**
33
     * The start location.
34
     *
35
     * @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
36
     */
37
    protected $start;
38
39
    /**
40
     * The end location.
41
     *
42
     * @var \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
43
     */
44
    protected $end;
45
46
    /**
47
     * The distance.
48
     *
49
     * @var \Arcanedev\GeoLocation\Entities\Measures\Distance
50
     */
51
    protected $distance;
52
53
    /**
54
     * The duration.
55
     *
56
     * @var \Arcanedev\GeoLocation\Entities\Measures\Duration
57
     */
58
    protected $duration;
59
60
    /**
61
     * The travel mode.
62
     *
63
     * @var string
64
     */
65
    protected $mode;
66
67
    /**
68
     * The instructions (HTML format).
69
     *
70
     * @var string
71
     */
72
    protected $instructions;
73
74
    /**
75
     * The polyline.
76
     *
77
     * @var array
78
     */
79
    protected $polyline;
80
81
    /* -----------------------------------------------------------------
82
     |  Constructor
83
     | -----------------------------------------------------------------
84
     */
85
86
    /**
87
     * Step constructor.
88
     *
89
     * @param  array  $data
90
     */
91 21
    public function __construct(array $data)
92
    {
93 21
        $this->start        = Position::createFromArray(Arr::get($data, 'start_location', ['lat' => 0, 'lng' => 0]));
94 21
        $this->end          = Position::createFromArray(Arr::get($data, 'end_location', ['lat' => 0, 'lng' => 0]));
95 21
        $this->distance     = Distance::makeFromArray(Arr::get($data, 'distance', ['text' => '', 'value' => 0]));
96 21
        $this->duration     = Duration::makeFromArray(Arr::get($data, 'duration', ['text' => '', 'value' => 0]));
97 21
        $this->mode         = Arr::get($data, 'travel_mode');
98 21
        $this->instructions = Arr::get($data, 'html_instructions');
99 21
        $this->polyline     = Arr::get($data, 'polyline', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Arr:...a, 'polyline', array()) of type * is incompatible with the declared type array of property $polyline.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
100 21
    }
101
102
    /* -----------------------------------------------------------------
103
     |  Getters & Setters
104
     | -----------------------------------------------------------------
105
     */
106
107
    /**
108
     * Get the start location.
109
     *
110
     * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
111
     */
112 9
    public function start()
113
    {
114 9
        return $this->start;
115
    }
116
117
    /**
118
     * Get the end location.
119
     *
120
     * @return \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position
121
     */
122 9
    public function end()
123
    {
124 9
        return $this->end;
125
    }
126
127
    /**
128
     * Get the distance.
129
     *
130
     * @return \Arcanedev\GeoLocation\Entities\Measures\Distance
131
     */
132 9
    public function distance()
133
    {
134 9
        return $this->distance;
135
    }
136
137
    /**
138
     * Get the duration.
139
     *
140
     * @return \Arcanedev\GeoLocation\Entities\Measures\Duration
141
     */
142 9
    public function duration()
143
    {
144 9
        return $this->duration;
145
    }
146
147
    /**
148
     * Get the traveling mode.
149
     *
150
     * @return string
151
     */
152 9
    public function mode()
153
    {
154 9
        return $this->mode;
155
    }
156
157
    /**
158
     * Get the instructions (HTML format)
159
     * @return string
160
     */
161 9
    public function instructions()
162
    {
163 9
        return $this->instructions;
164
    }
165
166
    /**
167
     * Get the polyline.
168
     *
169
     * @return array
170
     */
171 9
    public function polyline()
172
    {
173 9
        return $this->polyline;
174
    }
175
176
    /* -----------------------------------------------------------------
177
     |  Main Methods
178
     | -----------------------------------------------------------------
179
     */
180
181
    /**
182
     * Get the instance as an array.
183
     *
184
     * @return array
185
     */
186 6
    public function toArray()
187
    {
188
        return [
189 6
            'start'        => $this->start()->toArray(),
190 6
            'end'          => $this->end()->toArray(),
191 6
            'distance'     => $this->distance()->toArray(),
192 6
            'duration'     => $this->duration()->toArray(),
193 6
            'mode'         => $this->mode(),
194 6
            'instructions' => $this->instructions(),
195 6
            'polyline'     => $this->polyline(),
196 2
        ];
197
    }
198
}
199