Completed
Branch master (e25020)
by Richan
03:06
created

NegotiateLanguage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
1
<?php
2
3
namespace RichanFongdasen\I18n\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class NegotiateLanguage
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param \Closure                 $next
15
     *
16
     * @return mixed
17
     */
18
    public function handle(Request $request, Closure $next)
19
    {
20
        if (\I18n::routedLocale($request) === null) {
21
            $negotiator = \I18n::getConfig('negotiator');
22
            $locale = app($negotiator)->preferredLocale($request);
23
24
            return redirect(\I18n::url($request->getRequestUri(), $locale));
25
        }
26
27
        return $next($request);
28
    }
29
}
30