Completed
Pull Request — master (#4)
by ARCANEDEV
05:31
created

DirectionsResponse::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\GeoLocation\Google\Directions;
2
3
use Arcanedev\GeoLocation\Google\AbstractResponse;
4
5
/**
6
 * Class     DirectionsResponse
7
 *
8
 * @package  Arcanedev\GeoLocation\Google\Directions
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class DirectionsResponse extends AbstractResponse
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
18
    /** @var  array */
19
    protected $geocodedWaypoints;
20
21
    /**
22
     * The routes collection.
23
     *
24
     * @var \Arcanedev\GeoLocation\Google\Directions\Entities\RouteCollection
25
     */
26
    protected $routes;
27
28
    /* -----------------------------------------------------------------
29
     |  Getters & Setters
30
     | -----------------------------------------------------------------
31
     */
32
33
    /**
34
     * Get the geocoded waypoints.
35
     *
36
     * @return array
37
     */
38 6
    public function getGeocodedWaypoints()
39
    {
40 6
        return $this->get('geocoded_waypoints', []);
41
    }
42
43
    /**
44
     * Get the routes.
45
     *
46
     * @return \Arcanedev\GeoLocation\Google\Directions\Entities\RouteCollection
47
     */
48 21
    public function getRoutes()
49
    {
50 21
        if (is_null($this->routes)) {
51 21
            $this->routes = Entities\RouteCollection::load(
52 21
                $this->get('routes', [])
53 7
            );
54 7
        }
55
56 21
        return $this->routes;
57
    }
58
59
    /* -----------------------------------------------------------------
60
     |  Main Methods
61
     | -----------------------------------------------------------------
62
     */
63
64
    /**
65
     * Get the instance as an array.
66
     *
67
     * @return array
68
     */
69 6
    public function toArray()
70
    {
71
        return [
72 6
            'geocoded_waypoints' => $this->getGeocodedWaypoints(),
73 6
            'routes'             => $this->getRoutes()->toArray(),
74 2
        ];
75
    }
76
}
77