RedirectRequests   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 6
1
<?php
2
3
namespace Tofandel\Redirects\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class RedirectRequests
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  Request  $request
14
     * @param  Closure  $next
15
     * @return mixed
16
     */
17 6
    public function handle(Request $request, Closure $next)
18
    {
19 6
        if ($request->is(...config('redirects.exclude', []))) {
20 1
            return $next($request);
21
        }
22
23 5
        $path = urldecode($request->path());
24 5
        $redirect = app('redirect.model')->findValidOrNull($path);
0 ignored issues
show
Bug introduced by
The method findValidOrNull() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

24
        $redirect = app('redirect.model')->/** @scrutinizer ignore-call */ findValidOrNull($path);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
26 5
        if (! $redirect && $request->getQueryString()) {
27 1
            $path = $path.'?'.$request->getQueryString();
28 1
            $redirect = app('redirect.model')->findValidOrNull(urldecode($path));
29
        }
30
31 5
        if ($redirect && $redirect->exists) {
32 4
            return redirect($redirect->new_url, $redirect->status);
33
        }
34
35 2
        return $next($request);
36
    }
37
}
38