1 | <?php |
||
9 | class GeoIp |
||
10 | { |
||
11 | const LOCALE_DE = 'de'; |
||
12 | const LOCALE_EN = 'en'; |
||
13 | const LOCALE_FR = 'fr'; |
||
14 | const LOCALE_ES = 'es'; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $search; |
||
18 | |||
19 | /** @var string */ |
||
20 | protected $locale = 'en'; |
||
21 | |||
22 | /** @var Client */ |
||
23 | protected $client; |
||
24 | |||
25 | /** @var string */ |
||
26 | protected $baseUrl = 'http://ip-api.com'; |
||
27 | |||
28 | /** @var array */ |
||
29 | protected $fields = [ |
||
30 | 'status', |
||
31 | 'query', |
||
32 | 'country', |
||
33 | 'countryCode', |
||
34 | 'region', |
||
35 | 'regionName', |
||
36 | 'city', |
||
37 | 'zip', |
||
38 | 'lat', |
||
39 | 'lon', |
||
40 | 'timezone', |
||
41 | 'isp', |
||
42 | 'org', |
||
43 | 'as', |
||
44 | 'asname', |
||
45 | 'proxy', |
||
46 | 'reverse', |
||
47 | ]; |
||
48 | |||
49 | /** @var array */ |
||
50 | protected $allowedLocales = [ |
||
51 | self::LOCALE_DE, |
||
52 | self::LOCALE_EN, |
||
53 | self::LOCALE_FR, |
||
54 | self::LOCALE_ES |
||
55 | ]; |
||
56 | |||
57 | public static function for(string $search): self |
||
61 | |||
62 | public function __construct(string $search) |
||
68 | |||
69 | public function locale(string $locale): self |
||
79 | |||
80 | public function baseUrl(string $baseUrl): self |
||
86 | |||
87 | public function get(): array |
||
91 | |||
92 | protected function resolveSearch(string $search): string |
||
103 | |||
104 | protected function getResult(): array |
||
120 | |||
121 | protected function prepareClient(): void |
||
133 | } |
||
134 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.