Test Failed
Push — master ( ffc71e...1a0a2f )
by Koen
03:32
created

LocaleSelector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Config\Repository;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Config\Repository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Contracts\Translation\Translator;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Translation\Translator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
final class LocaleSelector
11
{
12
    /**
13
     * @var \Illuminate\Contracts\Config\Repository
14
     */
15
    protected $config;
16
17
    /**
18
     * @var \Illuminate\Contracts\Translation\Translator
19
     */
20
    protected $translator;
21
22
    /**
23
     * SetLocaleFromHeader constructor.
24
     *
25
     * @param  \Illuminate\Contracts\Config\Repository      $config
26
     * @param  \Illuminate\Contracts\Translation\Translator $translator
27
     */
28
    public function __construct(Repository $config, Translator $translator)
29
    {
30
        $this->config = $config;
31
        $this->translator = $translator;
32
    }
33
34
    /**
35
     * Handle an incoming request.
36
     *
37
     * @param  \Illuminate\Http\Request $request
38
     * @param  \Closure                 $next
39
     * @return mixed
40
     */
41
    public function handle(Request $request, Closure $next)
42
    {
43
        if ($request->headers->has('Accept-Language')) {
44
            $locale = $request->headers->get('Accept-Language');
45
46
            $this->config->set('app.locale', $locale);
47
48
            $this->translator->setLocale($locale);
49
        }
50
51
        return $next($request);
52
    }
53
}
54