Passed
Pull Request — master (#45)
by
unknown
06:02
created

RedirectCrawlers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 28
ccs 5
cts 9
cp 0.5556
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 3
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use App\Tournament;
6
use Closure;
7
use Illuminate\Support\Facades\Route;
8
9
class RedirectCrawlers
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request $request
15
     * @param  \Closure $next
16
     * @return mixed
17
     */
18 41
    public function handle($request, Closure $next)
19
    {
20
        $crawlers = [
21 41
            'facebookexternalhit/1.1',
22
            'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)',
23
            'Facebot',
24
            'Twitterbot',
25
        ];
26
27 41
        $userAgent = $request->header('User-Agent');
28
29 41
        if (str_contains($userAgent, $crawlers)) {
0 ignored issues
show
Bug introduced by
It seems like $userAgent can also be of type array; however, parameter $haystack of str_contains() does only seem to accept string, 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

29
        if (str_contains(/** @scrutinizer ignore-type */ $userAgent, $crawlers)) {
Loading history...
30
            switch (Route::getCurrentRoute()->getName()) {
31
                case "register.category":
32
                    $tournament = Tournament::where('slug', $request->tournament)->first();
33
                    return view('public/register', compact('tournament'));
34
            }
35
        }
36 41
        return $next($request);
37
    }
38
}
39