IpCheckCoordinates   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ipCheckCoordinates() 0 10 1
A __construct() 0 6 1
1
<?php
2
3
namespace KW\Models;
4
5
class IpCheckCoordinates
6
{
7
    /**
8
     * Check ip-type
9
     *
10
     * @return array
11
     */
12
13 9
    public function __construct($di)
14
    {
15 9
        $this->di = $di;
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
        //$this->ipCheckKey = $this->apiKeys->ipCheck;
17 9
        $this->baseUrl = "http://api.ipstack.com/";
0 ignored issues
show
Bug Best Practice introduced by
The property baseUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
18 9
        $this->apiKeys = $this->di->get("apikeys")["config"]["ipCheck"];
0 ignored issues
show
Bug Best Practice introduced by
The property apiKeys does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19 9
    }
20
21
    /**
22
     * Check ip-type
23
     *
24
     * @return array containing coordinates, country and town for IP if available
25
     */
26 3
    public function ipCheckCoordinates(string $ipnumber)
27
    {
28 3
        $accessKey = $this->apiKeys;
29 3
        $url = ($this->baseUrl . $ipnumber . "?access_key=" . $accessKey);
30
31 3
        $cURL = new CURL;
32 3
        $result = $cURL->req($url);
33 3
        $result = json_decode($result);
34
35 3
        return array($result->latitude, $result->longitude, $result->country_name, $result->city);
36
    }
37
}
38