Conditions | 5 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | public function location(Review $review): array |
||
14 | { |
||
15 | $location = get_post_meta($review->ID, '_geolocation', true); |
||
16 | if (!empty($location)) { |
||
17 | return glsr(GeolocationDefaults::class)->restrict($location); |
||
18 | } |
||
19 | $fallback = glsr(GeolocationDefaults::class)->defaults(); |
||
20 | if (Helper::isLocalIpAddress($review->ip_address)) { |
||
21 | return $fallback; |
||
22 | } |
||
23 | $response = glsr(Geolocation::class)->lookup($review->ip_address); |
||
24 | if ($response->failed()) { |
||
25 | return $fallback; |
||
26 | } |
||
27 | $location = $response->body(); |
||
28 | if (!$this->store($review, $location)) { |
||
29 | return $fallback; |
||
30 | } |
||
31 | return glsr(GeolocationDefaults::class)->restrict($location); |
||
32 | } |
||
49 |