Issues (20)

src/DeterminesGeoAccess.php (1 issue)

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
Bug Best Practice introduced by
The expression $countries of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
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