Completed
Push — master ( bf6805...5227c9 )
by Maxime
07:09
created

LanguageDetector::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
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.

This check looks from 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
}