IpVerifier   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setConfig() 0 3 1
A getJson() 0 8 2
1
<?php
2
3
namespace Linder\Model;
4
5
use Linder\Model\Curl;
6
7
class IpVerifier
8
{
9
    private $curl;
10
    private $config;
11
12
    /**
13
     * Constructor, allow for $di to be injected.
14
     *
15
     * @param Array $config a config file containing keys url / key
16
     */
17 2
    public function __construct($config)
18
    {
19 2
        $this->curl = new Curl();
20 2
        $this->config = $config;
21 2
    }
22
23
    /**
24
     * Set config
25
     */
26 2
    public function setConfig(Array $config)
27
    {
28 2
        $this->config = $config;
29 2
    }
30
31
    /**
32
     * This method takes one argument:
33
     * A string that we are going to check if its a valid ip-adress.
34
     * Returning an json with some information.
35
     *
36
     * @param string $value
37
     *
38
     * @return array
39
     */
40 2
    public function getJson($ip) : array
41
    {
42 2
        $url = $this->config["url"] . $ip;
43 2
        $res = $this->curl->single($url . $this->config["key"]);
44 2
        $res["domain"] = filter_var($ip, FILTER_VALIDATE_IP) ? gethostbyaddr($ip) : null;
45 2
        $res["url"] = $url;
46
47 2
        return $res;
48
    }
49
}
50