Completed
Push — master ( 80b7de...7dea50 )
by Steven
01:57
created

src/Drivers/FreeGeoIp.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Stevebauman\Location\Drivers;
4
5
use Illuminate\Support\Fluent;
6
use Stevebauman\Location\Position;
7
8
class FreeGeoIp extends Driver
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected function url()
14
    {
15
        return 'http://freegeoip.net/json/';
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 View Code Duplication
    protected function hydrate(Position $position, Fluent $location)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $position->countryCode = $location->country_code;
24
        $position->regionName = $location->region_name;
25
        $position->cityName = $location->city;
26
        $position->zipCode = $location->zip_code;
27
        $position->latitude = (string) $location->latitude;
28
        $position->longitude = (string) $location->longitude;
29
        $position->metroCode = (string) $location->metro_code;
30
        $position->areaCode = $location->area_code;
31
32
        return $position;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 View Code Duplication
    protected function process($ip)
39
    {
40
        try {
41
            $response = json_decode(file_get_contents($this->url().$ip), true);
42
43
            return new Fluent($response);
44
        } catch (\Exception $e) {
45
            return false;
46
        }
47
    }
48
}
49