GeoPlugin::process()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 3
nop 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