LaraCrafts /
laravel-geo-routes
| 1 | <?php |
||
| 2 | |||
| 3 | namespace LaraCrafts\GeoRoutes; |
||
| 4 | |||
| 5 | use Stevebauman\Location\Facades\Location; |
||
| 6 | |||
| 7 | trait DeterminesGeoAccess |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Determine if the request should be allowed through. |
||
| 11 | * |
||
| 12 | * @param array $countries |
||
| 13 | * @param string $strategy |
||
| 14 | * @return bool |
||
| 15 | */ |
||
| 16 | 176 | protected function shouldHaveAccess(array $countries, string $strategy) |
|
| 17 | { |
||
| 18 | 176 | if (!$countries) { |
|
|
0 ignored issues
–
show
|
|||
| 19 | 96 | return $strategy !== 'allow'; |
|
| 20 | } |
||
| 21 | |||
| 22 | 176 | $requestCountry = Location::get()->countryCode; |
|
| 23 | |||
| 24 | 176 | if ($strategy === 'allow') { |
|
| 25 | 128 | return in_array($requestCountry, $countries); |
|
| 26 | } |
||
| 27 | |||
| 28 | 48 | return !in_array($requestCountry, $countries); |
|
| 29 | } |
||
| 30 | } |
||
| 31 |
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.