Completed
Branch geo-attribute (e765b6)
by Raed
04:45
created

GeoRoutesMiddleware   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 35
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 5
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
     *
22
     * @return mixed
23
     */
24 72
    public function handle(Request $request, Closure $next)
25
    {
26 72
        $route = $request->route();
27
28 72
        if (!$route) {
29
            #TODO: Invoke the default callback.
30
            return abort(401);
1 ignored issue
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...
31
        }
32
33 72
        $geo = $route->getAction('geo');
34
35 72
        if ($this->shouldHaveAccess($request, (array)$geo['countries'], $geo['strategy'])) {
36 12
            return $next($request);
37
        }
38
39 60
        if (array_key_exists('callback', $geo) && $callback = $geo['callback']) {
0 ignored issues
show
Bug introduced by
It seems like $geo can also be of type null; however, parameter $search of array_key_exists() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        if (array_key_exists('callback', /** @scrutinizer ignore-type */ $geo) && $callback = $geo['callback']) {
Loading history...
40 36
            return call_user_func_array($callback[0], $callback[1]);
41
        }
42
43 24
        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...
44
    }
45
}
46