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

DirectionsResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 66
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getGeocodedWaypoints() 0 4 1
A getRoutes() 0 10 2
A toArray() 0 7 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