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

IpInfo   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 20.41 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 10
loc 49
rs 10
c 3
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 4 1
A process() 10 10 2
A hydrate() 0 21 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Stevebauman\Location\Drivers;
4
5
use Illuminate\Support\Fluent;
6
use Stevebauman\Location\Position;
7
8
class IpInfo extends Driver
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected function url()
14
    {
15
        return 'http://ipinfo.io/';
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function hydrate(Position $position, Fluent $location)
22
    {
23
        $position->countryCode = $location->country;
24
        $position->regionName = $location->region;
25
        $position->cityName = $location->city;
26
        $position->zipCode = $location->postal;
27
28
        if ($location->loc) {
29
            $coords = explode(',', $location->loc);
30
31
            if (array_key_exists(0, $coords)) {
32
                $position->latitude = $coords[0];
33
            }
34
35
            if (array_key_exists(1, $coords)) {
36
                $position->longitude = $coords[1];
37
            }
38
        }
39
40
        return $position;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 View Code Duplication
    protected function process($ip)
0 ignored issues
show
Duplication introduced by Steve Bauman
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...
47
    {
48
        try {
49
            $response = json_decode(file_get_contents($this->url().$ip));
50
51
            return new Fluent($response);
52
        } catch (\Exception $e) {
53
            return false;
54
        }
55
    }
56
}
57