NetAcuity   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 56
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getGeo() 0 5 1
1
<?php
2
3
namespace TraderInteractive\NetAcuity;
4
5
use TraderInteractive\NetAcuity\Databases\NetAcuityDatabaseInterface;
6
use TraderInteractive\Util;
7
use Exception;
8
9
/**
10
 * A client to access a NetAcuity server for geo-ip lookup.
11
 */
12
final class NetAcuity implements NetAcuityInterface
13
{
14
    /**
15
     * @var NetAcuityDatabaseInterface The Net Acuity Database to fetch data from.
16
     */
17
    private $database;
18
19
    /**
20
     * Create the NetAcuity client.
21
     *
22
     * @param NetAcuityDatabaseInterface $database     The Net Acuity Database to be used.
23
     *
24
     * @throws Exception
25
     */
26
    public function __construct(NetAcuityDatabaseInterface $database)
27
    {
28
        $this->database = $database;
29
    }
30
31
    /**
32
     * Gets the geo data for the given IP.
33
     *
34
     * Failures will be raised as exceptions.
35
     *
36
     * @param string $ip The ip address to lookup
37
     *
38
     * @return array {
39
     *     @type string $country
40
     *     @type string $region
41
     *     @type string $city
42
     *     @type string $conn-speed
43
     *     @type string $metro-code
44
     *     @type string $latitude
45
     *     @type string $longitude
46
     *     @type string $postal-code
47
     *     @type string $country-code
48
     *     @type string $region-code
49
     *     @type string $city-code
50
     *     @type string $continent-code
51
     *     @type string $two-letter-country
52
     *     @type string $area-code
53
     *     @type string $country-conf
54
     *     @type string $region-conf
55
     *     @type string $city-conf
56
     *     @type string $postal-conf
57
     *     @type string $gmt-offset
58
     *     @type string $in-dist
59
     *     @type string $timezone-name
60
     * }
61
     */
62
    public function getGeo(string $ip) : array
63
    {
64
        Util::throwIfNotType(['string' => $ip], true);
65
        return $this->database->fetch($ip);
66
    }
67
}
68