Completed
Push — master ( 2813e7...1616b2 )
by Choraimy
14s
created

DeterminesGeoAccess   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldHaveAccess() 0 13 3
1
<?php
2
3
namespace LaraCrafts\GeoRoutes;
4
5
use Illuminate\Http\Request;
6
use Stevebauman\Location\Facades\Location;
7
8
trait DeterminesGeoAccess
9
{
10
    /**
11
     * Determine if the request should be allowed through.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param array $countries
15
     * @param string $strategy
16
     * @return bool
17
     */
18 80
    protected function shouldHaveAccess(Request $request, array $countries, string $strategy)
19
    {
20 80
        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...
21 30
            return $strategy !== 'allow';
22
        }
23
24 80
        $requestCountry = Location::get($request->ip())->countryCode;
25
26 80
        if ($strategy === 'allow') {
27 50
            return in_array($requestCountry, $countries);
28
        }
29
30 30
        return !in_array($requestCountry, $countries);
31
    }
32
}
33