Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
CRAP | |
89.47% |
17 / 19 |
WSCoordinates | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
8.07 | |
89.47% |
17 / 19 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
fromInput | |
0.00% |
0 / 1 |
3.04 | |
83.33% |
5 / 6 |
|||
fromZipCode | |
0.00% |
0 / 1 |
1.04 | |
66.67% |
2 / 3 |
|||
fromIp | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiExternal\Services\Adserving; |
4 | |
5 | use Qmp\Laravel\MicroService\Client\Tools\Request as ClientRequest; |
6 | use Qmp\Laravel\MicroService\Client\Client; |
7 | |
8 | class WSCoordinates |
9 | { |
10 | protected $data; |
11 | |
12 | public function __construct(Data $data) |
13 | { |
14 | $this->data = $data; |
15 | } |
16 | |
17 | public function fromInput() |
18 | { |
19 | switch($this->data->input) { |
20 | case 'zip_code': // From zip_code |
21 | $this->fromZipCode(); |
22 | break; |
23 | default: // From ip |
24 | $this->fromIp(); |
25 | } |
26 | } |
27 | |
28 | protected function fromZipCode() |
29 | { |
30 | $this->data->debugData('No zip_code function implemented !'); |
31 | abort(410, "Gone"); |
32 | } |
33 | |
34 | protected function fromIp() |
35 | { |
36 | $response = $this->data->service(Data::SERVICE_GEOLOC_IP); |
37 | |
38 | if (!isset($response->content['coordinates']) || !is_array($response->content['coordinates'])) { |
39 | $this->data->debugData('Error on geolocation service :', [ |
40 | 'response' => $response->content |
41 | ]); |
42 | abort(410, "Gone"); |
43 | } |
44 | |
45 | $this->data->latitude = $response->content['coordinates']['lat']; |
46 | $this->data->longitude = $response->content['coordinates']['lon']; |
47 | } |
48 | } |