Total Complexity | 3 |
Total Lines | 90 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Response implements Arrayable |
||
8 | { |
||
9 | /** |
||
10 | * The IP address used to retrieve the geo-location. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | public $ip; |
||
15 | /** |
||
16 | * The country code. |
||
17 | * |
||
18 | * @var string|null |
||
19 | */ |
||
20 | public $countryCode; |
||
21 | /** |
||
22 | * The country name. |
||
23 | * |
||
24 | * @var string|null |
||
25 | */ |
||
26 | public $countryName; |
||
27 | /** |
||
28 | * The region name. |
||
29 | * |
||
30 | * @var string|null |
||
31 | */ |
||
32 | public $regionName; |
||
33 | /** |
||
34 | * The city name. |
||
35 | * |
||
36 | * @var string|null |
||
37 | */ |
||
38 | public $cityName; |
||
39 | /** |
||
40 | * The zip code. |
||
41 | * |
||
42 | * @var string|null |
||
43 | */ |
||
44 | public $zipCode; |
||
45 | /** |
||
46 | * The latitude. |
||
47 | * |
||
48 | * @var string|null |
||
49 | */ |
||
50 | public $latitude; |
||
51 | /** |
||
52 | * The longitude. |
||
53 | * |
||
54 | * @var string|null |
||
55 | */ |
||
56 | public $longitude; |
||
57 | |||
58 | /** |
||
59 | * Response constructor. |
||
60 | * |
||
61 | * @param array $driverResponse |
||
62 | */ |
||
63 | public function __construct($driverResponse) |
||
64 | { |
||
65 | $this->ip = $driverResponse['ip'] ?? $driverResponse['IPv4']; |
||
66 | $this->countryCode = $driverResponse['country_code']; |
||
67 | $this->countryName = $driverResponse['country_name']; |
||
68 | $this->regionName = $driverResponse['state']; |
||
69 | $this->cityName = $driverResponse['city']; |
||
70 | $this->zipCode = $driverResponse['postal']; |
||
71 | $this->latitude = $driverResponse['latitude']; |
||
72 | $this->longitude = $driverResponse['longitude']; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Determine if the response is empty. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function isEmpty() |
||
81 | { |
||
82 | $data = $this->toArray(); |
||
83 | |||
84 | unset($data['ip']); |
||
85 | |||
86 | return empty(array_filter($data)); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the instance as an array. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | public function toArray() |
||
97 | } |
||
98 | } |
||
99 |