Completed
Pull Request — master (#4)
by ARCANEDEV
01:52
created

Route   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 103
rs 10
c 0
b 0
f 0

6 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
1
<?php namespace Arcanedev\GeoLocation\Google\Directions\Entities;
2
use Arcanedev\GeoLocation\Entities\Position;
3
use Arcanedev\GeoLocation\Entities\Viewport;
4
use Illuminate\Support\Arr;
5
6
/**
7
 * Class     Route
8
 *
9
 * @package  Arcanedev\GeoLocation\Google\Directions\Entities
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class Route
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * The route summary.
21
     *
22
     * @var string
23
     */
24
    protected $summary;
25
26
    /**
27
     * @var \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection
28
     */
29
    protected $legs;
30
31
    /** @var string */
32
    protected $copyrights;
33
34
    /** @var  \Arcanedev\GeoLocation\Entities\Viewport */
35
    protected $bounds;
36
37
    /* -----------------------------------------------------------------
38
     |  Constructor
39
     | -----------------------------------------------------------------
40
     */
41
42
    /**
43
     * Route constructor.
44
     *
45
     * @param  array  $data
46
     */
47
    public function __construct(array $data)
48
    {
49
        $this->summary    = Arr::get($data, 'summary', '');
50
        $this->legs       = LegCollection::load(Arr::get($data, 'legs', []));
51
        $this->copyrights = Arr::get($data, 'copyrights');
52
        $this->setBounds(Arr::get($data, 'bounds', []));
53
    }
54
55
    /* -----------------------------------------------------------------
56
     |  Getters & Setters
57
     | -----------------------------------------------------------------
58
     */
59
60
    /**
61
     * Get the route summary.
62
     *
63
     * @return string
64
     */
65
    public function summary()
66
    {
67
        return $this->summary;
68
    }
69
70
    /**
71
     * @param  array  $bounds
72
     *
73
     * @return self
74
     */
75
    private function setBounds(array $bounds)
76
    {
77
        $this->bounds = Viewport::create(
78
            Position::create(Arr::get($bounds, 'northeast.lat'), Arr::get($bounds, 'northeast.lng')),
79
            Position::create(Arr::get($bounds, 'southwest.lat'), Arr::get($bounds, 'southwest.lng'))
80
        );
81
82
        return $this;
83
    }
84
85
    /**
86
     * Get the leg collection.
87
     *
88
     * @return \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection
89
     */
90
    public function legs()
91
    {
92
        return $this->legs;
93
    }
94
95
    /**
96
     * Get the copyrights.
97
     *
98
     * @return string
99
     */
100
    public function copyrights()
101
    {
102
        return $this->copyrights;
103
    }
104
105
    /**
106
     * Get the bounds.
107
     *
108
     * @return \Arcanedev\GeoLocation\Entities\Viewport
109
     */
110
    public function bounds()
111
    {
112
        return $this->bounds;
113
    }
114
}
115