IpCheckCoordinates::ipCheckCoordinates()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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