Passed
Pull Request — master (#29)
by Raed
08:15
created

DeterminesGeoAccess::shouldHaveAccess()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 10
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 array $countries
14
     * @param string $strategy
15
     * @return bool
16
     */
17 60
    protected function shouldHaveAccess(array $countries, string $strategy)
18
    {
19 60
        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...
20 36
            return $strategy !== 'allow';
21
        }
22
23 24
        $requestCountry = Location::get()->countryCode;
24
25 24
        if ($strategy === 'allow') {
26
            return in_array($requestCountry, $countries);
27
        }
28
29 24
        return !in_array($requestCountry, $countries);
30
    }
31
}
32