Locator::getLocation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 19
ccs 13
cts 13
cp 1
crap 1
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Jodn14\Models;
4
5
/**
6
 * Model for IP Locator logic
7
 */
8
class Locator
9
{
10
    /*
11
     * Private $access_key contains key to third party API - ipstack.com
12
     */
13
14
    private $accessKey = "26ac05fc6257e7fc03c369cec5552b0a";
15
16
    /**
17
     * calls ipstack with ip parameter
18
     *
19
     * @param string ipAddress
0 ignored issues
show
Bug introduced by
The type Jodn14\Models\ipAddress was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     * @return array
21
     */
22 6
    public function getLocation($ipAddress) : array
23
    {
24 6
        $apiCall = curl_init('http://api.ipstack.com/'.$ipAddress.'?access_key='.$this->accessKey.'');
25 6
        curl_setopt($apiCall, CURLOPT_RETURNTRANSFER, true);
26
27 6
        $json = curl_exec($apiCall);
28 6
        curl_close($apiCall);
29
30 6
        $apiResult = json_decode($json, true);
31
        $filtered = [
32 6
            "ip"           => $apiResult["ip"],
33 6
            "type"         => $apiResult["type"],
34 6
            "country_name" => $apiResult["country_name"],
35 6
            "city"         => $apiResult["city"],
36 6
            "latitude"     => $apiResult["latitude"],
37 6
            "longitud"     => $apiResult["longitude"]
38
        ];
39
40 6
        return $filtered;
41
    }
42
}
43