GeoPlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
c 0
b 0
f 0
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 3 1
A process() 0 8 2
A hydrate() 0 12 1
1
<?php
2
3
namespace Stevebauman\Location\Drivers;
4
5
use Exception;
6
use Illuminate\Support\Fluent;
7
use Stevebauman\Location\Position;
8
9
class GeoPlugin extends Driver
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected function url($ip)
15
    {
16
        return "http://www.geoplugin.net/php.gp?ip=$ip";
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected function hydrate(Position $position, Fluent $location)
23
    {
24
        $position->countryCode = $location->geoplugin_countryCode;
25
        $position->countryName = $location->geoplugin_countryName;
26
        $position->regionName = $location->geoplugin_regionName;
27
        $position->regionCode = $location->geoplugin_regionCode;
28
        $position->cityName = $location->geoplugin_city;
29
        $position->latitude = $location->geoplugin_latitude;
30
        $position->longitude = $location->geoplugin_longitude;
31
        $position->areaCode = $location->geoplugin_areaCode;
32
33
        return $position;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function process($ip)
40
    {
41
        try {
42
            $response = unserialize($this->getUrlContent($this->url($ip)));
43
44
            return new Fluent($response);
45
        } catch (Exception $e) {
46
            return false;
47
        }
48
    }
49
}
50