IpLocator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGeoInfo() 0 7 1
A __construct() 0 4 1
1
<?php
2
3
namespace EVB\Weather;
4
5
6
/**
7
 * Simple class for locating IP-addresses.
8
 */
9
class IpLocator
10
{
11
    private const IPSTACK_BASE_URL = "http://api.ipstack.com/";
12
    private $apiKey;
13
    private $curl;
14
15
16 1
    public function __construct($apiKey, $curl)
17
    {
18 1
        $this->apiKey = $apiKey;
19 1
        $this->curl = $curl;
20 1
    }
21
22
    /**
23
     * Gets geographical information from ipstack for the supplied IP-address.
24
     *
25
     * @param string $ip
26
     * @return array
27
     */
28 1
    public function getGeoInfo(string $ip) : array
29
    {
30 1
        $url = self::IPSTACK_BASE_URL . $ip . "?access_key=" . $this->apiKey;
31
32 1
        $response = \json_decode($this->curl->fetch($url), true);
33
34 1
        return $response;
35
    }
36
}
37