Completed
Push — master ( 1bd981...d065a3 )
by Choraimy
15s
created

GeoRoutesMiddleware::shouldHaveAccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaraCrafts\GeoRoutes\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use LaraCrafts\GeoRoutes\DeterminesGeoAccess;
8
9
class GeoRoutesMiddleware
10
{
11
    use DeterminesGeoAccess;
0 ignored issues
show
Bug introduced by
The trait LaraCrafts\GeoRoutes\DeterminesGeoAccess requires the property $countryCode which is not provided by LaraCrafts\GeoRoutes\Htt...are\GeoRoutesMiddleware.
Loading history...
12
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param \Illuminate\Http\Request $request
17
     * @param \Closure $next
18
     * @param string $strategy
19
     * @param string $countries
20
     * @param string|null $callback
21
     * @return mixed
22
     */
23 9
    public function handle(Request $request, Closure $next, string $strategy, string $countries, string $callback = null)
24
    {
25 9
        $countries = explode('&', $countries);
26
27 9
        if ($this->shouldHaveAccess($request, $countries, $strategy)) {
28 3
            return $next($request);
29
        }
30
31 6
        if ($callback && $callback = unserialize($callback)) {
32 3
            return call_user_func_array($callback[0], $callback[1] ?? []);
33
        }
34
35 3
        return abort(401);
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort(401) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
    }
37
}
38