DeterminesGeoAccess   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldHaveAccess() 0 13 3
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