LocaleMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
1
<?php
2
3
namespace JosephNC\Translation\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use JosephNC\Translation\Facades\Translation;
8
9
class LocaleMiddleware
10
{
11
    /**
12
     * Sets the locale cookie on every request depending
13
     * on the locale supplied in the route prefix.
14
     *
15
     * @param Request $request
16
     * @param Closure $next
17
     *
18
     * @return mixed
19
     */
20
    public function handle(Request $request, Closure $next)
21
    {
22
        $lang = Translation::getRoutePrefix() ?? '';
0 ignored issues
show
Bug introduced by
The method getRoutePrefix() does not exist on JosephNC\Translation\Facades\Translation. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

22
        $lang = Translation::/** @scrutinizer ignore-call */ getRoutePrefix() ?? '';
Loading history...
23
        $lang = empty( $lang ) ? Translation::getLocale() : $lang;
0 ignored issues
show
Bug introduced by
The method getLocale() does not exist on JosephNC\Translation\Facades\Translation. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

23
        $lang = empty( $lang ) ? Translation::/** @scrutinizer ignore-call */ getLocale() : $lang;
Loading history...
24
25
        Translation::setLocale( $lang );
0 ignored issues
show
Bug introduced by
The method setLocale() does not exist on JosephNC\Translation\Facades\Translation. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

25
        Translation::/** @scrutinizer ignore-call */ 
26
                     setLocale( $lang );
Loading history...
26
27
        return $next($request);
28
    }
29
}
30