1 | <?php |
||
14 | final class NetAcuity |
||
15 | { |
||
16 | /** |
||
17 | * @var string Net Acuity's Edge DB Code. |
||
18 | */ |
||
19 | const NETACUITY_EDGE_DB_ID = 4; |
||
20 | |||
21 | /** |
||
22 | * A Collection of implemented DBs referred to by the NetAcuity DB Id. |
||
23 | */ |
||
24 | const IMPLEMENTED_DBS = [ |
||
25 | self::NETACUITY_EDGE_DB_ID |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @var string The API User token provided by NetAcuity. |
||
30 | */ |
||
31 | private $_apiUserToken; |
||
32 | |||
33 | /** |
||
34 | * @var Client The Guzzle Client to be used. |
||
35 | */ |
||
36 | private $_client; |
||
37 | |||
38 | /** |
||
39 | * @var string The NetAcuity database to fetch data from. |
||
40 | */ |
||
41 | private $_dbId; |
||
42 | |||
43 | /** |
||
44 | * Create the NetAcuity client. |
||
45 | * |
||
46 | * @param ClientInterface $client The guzzle client to be used. Needs no configuration from the calling application. |
||
47 | * @param string $apiUserToken The passed in API User Token specific to the calling application or organization. |
||
48 | * @param string $dbIdentifier The netacuity database identifier, ex: NetAcuity::NETACUITY_EDGE_DB_ID |
||
49 | */ |
||
50 | public function __construct(ClientInterface $client, string $apiUserToken, string $dbIdentifier) |
||
60 | |||
61 | /** |
||
62 | * Gets the geo data for the given IP. |
||
63 | * |
||
64 | * Failures will be raised as exceptions. |
||
65 | * |
||
66 | * @param string $ip The ip address to lookup |
||
67 | * |
||
68 | * @return array { |
||
69 | * @type string $country |
||
70 | * @type string $region |
||
71 | * @type string $city |
||
72 | * @type string $conn-speed |
||
73 | * @type string $metro-code |
||
74 | * @type string $latitude |
||
75 | * @type string $longitude |
||
76 | * @type string $postal-code |
||
77 | * @type string $country-code |
||
78 | * @type string $region-code |
||
79 | * @type string $city-code |
||
80 | * @type string $continent-code |
||
81 | * @type string $two-letter-country |
||
82 | * @type string $internal-code |
||
83 | * @type string $area-code |
||
84 | * @type string $country-conf |
||
85 | * @type string $region-conf |
||
86 | * @type string $city-conf |
||
87 | * @type string $postal-conf |
||
88 | * @type string $gmt-offset |
||
89 | * @type string $in-dist |
||
90 | * @type string $timezone-name |
||
91 | * } |
||
92 | */ |
||
93 | public function getGeo(string $ip) |
||
110 | |||
111 | private function _buildQuery(string $userToken, string $db, string $ip, bool $asJson = true) : string |
||
117 | |||
118 | /** |
||
119 | * @param ClientException $e The thrown exception for handling. |
||
120 | * |
||
121 | * @throws Exception A formatted exception masking the API User Token in the event that it becomes invalid. |
||
122 | */ |
||
123 | private function _handleGuzzleException(ClientException $e) |
||
137 | |||
138 | /** |
||
139 | * Parses the response into an array using the field definition. |
||
140 | * |
||
141 | * @param array $response The response from NetAcuity. |
||
142 | * |
||
143 | * @return array The response where the keys are from $fields and the values are from the $response. |
||
144 | * @throws Exception |
||
145 | */ |
||
146 | private function _parseBody(array $response) |
||
178 | } |
||
179 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.