IpVerifier::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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