Ip2c::dec()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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