Ip2c   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 58
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A self() 0 4 1
A ip() 0 4 1
A dec() 0 4 1
A doRequest() 0 4 1
1
<?php
2
3
namespace Ip2c;
4
5
use Ip2c\Http\Request;
6
use Ip2c\Http\Response;
7
use Ip2c\Ip\IpUtil;
8
9
class Ip2c
10
{
11
    private $ip2cBaseUrl = 'http://ip2c.org';
12
    private $queryStringSelf = 'self';
13
    private $queryStringDec = 'dec=';
14
15
    /** @var Request */
16
    private $request;
17
    /** @var IpUtil */
18
    private $ipUtil;
19
20
    /**
21
     * Ip2c constructor.
22
     * @param Request $request
23
     * @param IpUtil $ipUtil
24
     */
25 6
    public function __construct(Request $request, IpUtil $ipUtil)
26
    {
27 6
        $this->request = $request;
28 6
        $this->ipUtil = $ipUtil;
29 6
    }
30
31
    /**
32
     * @return Response
33
     */
34 2
    public function self()
35
    {
36 2
        return $this->doRequest($this->queryStringSelf);
37
    }
38
39
    /**
40
     * @param string $ip
41
     * @return Response
42
     */
43 2
    public function ip($ip)
44
    {
45 2
        return $this->dec($this->ipUtil->ip2long($ip));
0 ignored issues
show
Bug introduced by
It seems like $this->ipUtil->ip2long($ip) targeting Ip2c\Ip\IpUtil::ip2long() can also be of type double or false; however, Ip2c\Ip2c::dec() does only seem to accept integer, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
46
    }
47
48
    /**
49
     * @param int $ip2long
50
     * @return Response
51
     */
52 3
    public function dec($ip2long)
53
    {
54 3
        return $this->doRequest($this->queryStringDec . $ip2long);
55
    }
56
57
    /**
58
     * @param string $queryString
59
     * @return Response
60
     * @throws \Exception
61
     */
62 4
    private function doRequest($queryString)
63
    {
64 4
        return new Response($this->request->doRequest($this->ip2cBaseUrl, $queryString));
65
    }
66
}
67