Completed
Push — master ( 0885cd...ef8e35 )
by Antoine
02:22
created

BatchGeocoded   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.83%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 3
dl 0
loc 189
c 0
b 0
f 0
ccs 46
cts 48
cp 0.9583
rs 10

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

 

OSZAR »