LanguageDetector::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 10
cc 3
nc 3
nop 2
crap 12
1
<?php
2
3
namespace Distilleries\Expendable\Http\Middleware;
4
5
use Closure;
6
use Distilleries\Expendable\Models\Language;
7
use Illuminate\Contracts\Foundation\Application;
8
9
class LanguageDetector
10
{
11
    protected $app;
12
13
    public function __construct(Application $app)
14
    {
15
        $this->app = $app;
16
    }
17
18
    /**
19
     * Handle an incoming request.
20
     *
21
     * @param \Illuminate\Http\Request $request
22
     * @param \Closure $next
23
     * @return mixed
24
     */
25
    public function handle($request, Closure $next)
0 ignored issues
show
Unused Code introduced by
The parameter $next is not used and could be removed. ( Ignorable by Annotation )

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

25
    public function handle($request, /** @scrutinizer ignore-unused */ Closure $next)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
28
        preg_match_all('/(\W|^)([a-z]{2})([^a-z]|$)/six', $request->server->get('HTTP_ACCEPT_LANGUAGE'), $m, PREG_PATTERN_ORDER);
29
30
        $user_langs = $m[2];
31
        if (!empty($user_langs[0])) {
32
            $total = Language::where('iso', '=', $user_langs[0])->count();
33
            if ($total > 0) {
34
                return redirect()->to('/'.$user_langs[0]);
35
            }
36
        }
37
38
        return redirect()->to('/fr');
39
    }
40
}