RedirectRequests::handle()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 5
nop 2
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
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