Completed
Push — master ( ef8e35...28395c )
by Antoine
05:19
created

BatchGeocoded   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 97.78%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 3
dl 0
loc 189
ccs 44
cts 45
cp 0.9778
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getProviderName() 0 4 1
A setProviderName() 0 4 1
A getQuery() 0 4 1
A setQuery() 0 4 1
A getExceptionMessage() 0 4 1
A setExceptionMessage() 0 4 1
A getAddress() 0 4 1
A setAddress() 0 4 1
A getCoordinates() 0 8 2
A getLatitude() 0 8 2
A getLongitude() 0 8 2
A fromArray() 0 15 4
A __call() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the Geotools library.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\Geotools\Batch;
13
14
use Geocoder\Location;
15
use Geocoder\Model\Address;
16
use Geocoder\Model\Coordinates;
17
18
/**
19
 * BatchGeocoded class
20
 *
21
 * @author Antoine Corcy <[email protected]>
22
 */
23
class BatchGeocoded
24
{
25
    /**
26
     * The name of the provider.
27
     *
28
     * @var string
29
     */
30
    protected $providerName;
31
32
    /**
33
     * The query.
34
     *
35
     * @var string
36
     */
37
    protected $query;
38
39
    /**
40
     * The exception message.
41
     *
42
     * @var string
43
     */
44
    protected $exception;
45
46
    /**
47
     * The Location object.
48
     *
49
     * @var Location
50
     */
51
    protected $address;
52
53
    /**
54
     * Get the name of the provider.
55
     *
56
     * @return string The name of the provider.
57
     */
58 13
    public function getProviderName()
59
    {
60 13
        return $this->providerName;
61
    }
62
63
    /**
64
     * Set the name of the provider.
65
     *
66
     * @param string $providerName The name of the provider.
67
     */
68 16
    public function setProviderName($providerName)
69
    {
70 16
        $this->providerName = $providerName;
71 16
    }
72
73
    /**
74
     * Get the query.
75
     *
76
     * @return string The query.
77
     */
78 13
    public function getQuery()
79
    {
80 13
        return $this->query;
81
    }
82
83
    /**
84
     * Set the query.
85
     *
86
     * @param string $query The query.
87
     */
88 16
    public function setQuery($query)
89
    {
90 16
        $this->query = $query;
91 16
    }
92
93
    /**
94
     * Get the exception message.
95
     *
96
     * @return string The exception message.
97
     */
98 5
    public function getExceptionMessage()
99
    {
100 5
        return $this->exception;
101
    }
102
103
    /**
104
     * Set the exception message.
105
     *
106
     * @param string $exception The exception message.
107
     */
108 16
    public function setExceptionMessage($exception)
109
    {
110 16
        $this->exception = $exception;
111 16
    }
112
113
    /**
114
     * Get the address
115
     *
116
     * @return Location
117
     */
118 4
    public function getAddress()
119
    {
120 4
        return $this->address;
121
    }
122
123
    /**
124
     * Set the address
125
     *
126
     * @param Location $address
127
     */
128 14
    public function setAddress($address)
129
    {
130 14
        $this->address = $address;
131 14
    }
132
133
    /**
134
     * Returns an array of coordinates (latitude, longitude).
135
     *
136
     * @return Coordinates|null
137
     */
138 21
    public function getCoordinates()
139
    {
140 21
        if (null === $this->address) {
141 8
            return null;
142
        }
143
144 13
        return $this->address->getCoordinates();
145
    }
146
147
    /**
148
     * Returns the latitude value.
149
     *
150
     * @return double
151
     */
152 21
    public function getLatitude()
153
    {
154 21
        if (null === $coordinates = $this->getCoordinates()) {
155 10
            return null;
156
        }
157
158 11
        return $coordinates->getLatitude();
159
    }
160
161
    /**
162
     * Returns the longitude value.
163
     *
164
     * @return double
165
     */
166 21
    public function getLongitude()
167
    {
168 21
        if (null === $coordinates = $this->getCoordinates()) {
169 10
            return null;
170
        }
171
172 11
        return $coordinates->getLongitude();
173
    }
174
175
    /**
176
     * Create an instance from an array, used from cache libraries.
177
     *
178
     * @param array $data
179
     */
180 6
    public function fromArray(array $data = [])
181
    {
182 6
        if (isset($data['providerName'])) {
183 5
            $this->providerName = $data['providerName'];
184
        }
185 6
        if (isset($data['query'])) {
186 5
            $this->query = $data['query'];
187
        }
188 6
        if (isset($data['exception'])) {
189 1
            $this->exception = $data['exception'];
190
        }
191
192
        // Shortcut to create the address and set it in this class
193 6
        $this->setAddress(Address::createFromArray($data['address']));
194 6
    }
195
196
	/**
197
     * Router all other methods call directly to our address object
198
     *
199
     * @param $method
200
     * @param $args
201
     * @return mixed
202
     */
203 1
    public function __call($method, $args)
204
    {
205 1
        if (null === $this->address) {
206
            return null;
207
        }
208
209 1
        return call_user_func_array([$this->address, $method], $args);
210
    }
211
}
212