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

Route   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 140
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A summary() 0 4 1
A setBounds() 0 9 1
A legs() 0 4 1
A copyrights() 0 4 1
A bounds() 0 4 1
A toArray() 0 9 1
1
<?php namespace Arcanedev\GeoLocation\Google\Directions\Entities;
2
3
use Arcanedev\GeoLocation\Entities\Coordinates\Position;
4
use Arcanedev\GeoLocation\Entities\Coordinates\Viewport;
5
use Arcanedev\GeoLocation\Traits\CanBeJsonable;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Contracts\Support\Jsonable;
8
use Illuminate\Support\Arr;
9
use JsonSerializable;
10
11
/**
12
 * Class     Route
13
 *
14
 * @package  Arcanedev\GeoLocation\Google\Directions\Entities
15
 * @author   ARCANEDEV <[email protected]>
16
 */
17
class Route implements Arrayable, Jsonable, JsonSerializable
18
{
19
    /* -----------------------------------------------------------------
20
     |  Traits
21
     | -----------------------------------------------------------------
22
     */
23
24
    use CanBeJsonable;
25
26
    /* -----------------------------------------------------------------
27
     |  Properties
28
     | -----------------------------------------------------------------
29
     */
30
31
    /**
32
     * The summary.
33
     *
34
     * @var string
35
     */
36
    protected $summary;
37
38
    /**
39
     * The legs.
40
     *
41
     * @var \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection
42
     */
43
    protected $legs;
44
45
    /**
46
     * The copyrights.
47
     *
48
     * @var string
49
     */
50
    protected $copyrights;
51
52
    /**
53
     * The bounds.
54
     *
55
     * @var  \Arcanedev\GeoLocation\Entities\Coordinates\Viewport
56
     */
57
    protected $bounds;
58
59
    /* -----------------------------------------------------------------
60
     |  Constructor
61
     | -----------------------------------------------------------------
62
     */
63
64
    /**
65
     * Route constructor.
66
     *
67
     * @param  array  $data
68
     */
69 21
    public function __construct(array $data)
70
    {
71 21
        $this->summary    = Arr::get($data, 'summary', '');
72 21
        $this->legs       = LegCollection::load(Arr::get($data, 'legs', []));
73 21
        $this->copyrights = Arr::get($data, 'copyrights');
74 21
        $this->setBounds(Arr::get($data, 'bounds', []));
75 21
    }
76
77
    /* -----------------------------------------------------------------
78
     |  Getters & Setters
79
     | -----------------------------------------------------------------
80
     */
81
82
    /**
83
     * Get the route summary.
84
     *
85
     * @return string
86
     */
87 9
    public function summary()
88
    {
89 9
        return $this->summary;
90
    }
91
92
    /**
93
     * @param  array  $bounds
94
     *
95
     * @return self
96
     */
97 21
    private function setBounds(array $bounds)
98
    {
99 21
        $this->bounds = Viewport::create(
100 21
            Position::create(Arr::get($bounds, 'northeast.lat'), Arr::get($bounds, 'northeast.lng')),
101 21
            Position::create(Arr::get($bounds, 'southwest.lat'), Arr::get($bounds, 'southwest.lng'))
102 7
        );
103
104 21
        return $this;
105
    }
106
107
    /**
108
     * Get the leg collection.
109
     *
110
     * @return \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection
111
     */
112 9
    public function legs()
113
    {
114 9
        return $this->legs;
115
    }
116
117
    /**
118
     * Get the copyrights.
119
     *
120
     * @return string
121
     */
122 9
    public function copyrights()
123
    {
124 9
        return $this->copyrights;
125
    }
126
127
    /**
128
     * Get the bounds.
129
     *
130
     * @return \Arcanedev\GeoLocation\Entities\Coordinates\Viewport
131
     */
132 9
    public function bounds()
133
    {
134 9
        return $this->bounds;
135
    }
136
137
    /* -----------------------------------------------------------------
138
     |  Main Methods
139
     | -----------------------------------------------------------------
140
     */
141
142
    /**
143
     * Get the instance as an array.
144
     *
145
     * @return array
146
     */
147 6
    public function toArray()
148
    {
149
        return [
150 6
            'summary'    => $this->summary(),
151 6
            'legs'       => $this->legs()->toArray(),
152 6
            'copyrights' => $this->copyrights(),
153 6
            'bounds'     => $this->bounds()->toArray(),
154 2
        ];
155
    }
156
}
157