Conditions | 6 |
Paths | 8 |
Total Lines | 21 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | |||
19 | public function getCountryCode(string $ip): ?string |
||
20 | { |
||
21 | if ('' === $ip) { |
||
22 | return null; |
||
23 | } |
||
24 | $urlService = 'http://www.geoplugin.net/php.gp?ip=' . $ip; |
||
25 | try { |
||
26 | $request = $this->requestFactory->createRequest('GET', $urlService); |
||
27 | $response = GuzzleClientFactory::getClient()->send($request); |
||
28 | |||
29 | if (200 !== $response->getStatusCode()) { |
||
30 | throw new IpLocationException('Missing information in response', 123781); |
||
31 | } |
||
32 | $result = (array)unserialize((string)$response->getBody()); |
||
33 | |||
34 | if (empty($result) || 404 === (int)$result['geoplugin_status']) { |
||
35 | throw new IpLocationException('No valid data', 162378); |
||
36 | } |
||
37 | |||
38 | return $result['geoplugin_countryCode'] ?? null; |
||
39 | } catch (IpLocationException $exc) { |
||
44 |