IPStackFinder::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Arimolzer\IPStackFinder;
4
5
use GuzzleHttp\Client;
6
7
/**
8
 * Class IPStackFinder
9
 * @package Arimolzer\IPStackFinder
10
 */
11
class IPStackFinder
12
{
13
    /** @var Client $client */
14
    public $client;
15
16
    /**
17
     * IPStackHelper constructor.
18
     * @param Client $client
19
     */
20
    public function __construct(Client $client)
21
    {
22
        $this->client = $client;
23
    }
24
25
    /**
26
     * Get the API response from ipstack.com and return in php associative array format.
27
     * @param $ipAddress
28
     * @return array
29
     * @throws \GuzzleHttp\Exception\GuzzleException
30
     */
31
    public function get($ipAddress) : array
32
    {
33
        /** @var string $responseJson */
34
        $responseJson = $this->client
35
            ->request('GET', $ipAddress)
36
            ->getBody()
37
            ->getContents();
38
39
        /** @var array */
40
        return json_decode($responseJson, true);
41
    }
42
}
43