Completed
Pull Request — master (#19)
by Choraimy
17:14 queued 15:17
created

GeoRoutesMiddleware   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 51
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCountries() 0 3 1
A handle() 0 14 4
A getStrategy() 0 3 1
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
    protected $countries;
14
    protected $strategy;
15
16
    /**
17
     * Handle an incoming request.
18
     *
19
     * @param \Illuminate\Http\Request $request
20
     * @param \Closure $next
21
     * @param string $strategy
22
     * @param string $countries
23
     * @param string|null $callback
24
     * @return mixed
25
     */
26 15
    public function handle(Request $request, Closure $next, string $strategy, string $countries, string $callback = null)
27
    {
28 15
        $this->countries = explode('&', $countries);
29 15
        $this->strategy = $strategy;
30
31 15
        if ($this->shouldHaveAccess($request)) {
32 3
            return $next($request);
33
        }
34
35 12
        if ($callback && $callback = unserialize($callback)) {
36 7
            return call_user_func_array($callback[0], $callback[1] ?? []);
37
        }
38
39 5
        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...
40
    }
41
42
    /**
43
     * Get the countries.
44
     *
45
     * @return string[]
46
     */
47 15
    public function getCountries()
48
    {
49 15
        return $this->countries;
50
    }
51
52
    /**
53
     * Get the strategy.
54
     *
55
     * @return string
56
     */
57 15
    public function getStrategy()
58
    {
59 15
        return $this->strategy;
60
    }
61
}
62