1 | <?php |
||||||
2 | |||||||
3 | namespace Translation\Http\Middleware; |
||||||
4 | |||||||
5 | use Closure; |
||||||
6 | use Illuminate\Http\Request; |
||||||
0 ignored issues
–
show
|
|||||||
7 | use Translation\Facades\Translation; |
||||||
8 | use Illuminate\Contracts\Auth\Guard; |
||||||
9 | use Illuminate\Contracts\Routing\ResponseFactory; |
||||||
10 | use Illuminate\Support\Facades\Config; |
||||||
11 | use Illuminate\Support\Facades\Cookie; |
||||||
12 | |||||||
13 | class LocaleMiddleware |
||||||
14 | { |
||||||
15 | /** |
||||||
16 | * The Guard implementation. |
||||||
17 | * |
||||||
18 | * @var Guard |
||||||
19 | */ |
||||||
20 | protected $auth; |
||||||
21 | |||||||
22 | /** |
||||||
23 | * The response factory implementation. |
||||||
24 | * |
||||||
25 | * @var ResponseFactory |
||||||
26 | */ |
||||||
27 | protected $response; |
||||||
28 | |||||||
29 | /** |
||||||
30 | * Create a new filter instance. |
||||||
31 | * |
||||||
32 | * @param Guard $auth |
||||||
33 | * @param ResponseFactory $response |
||||||
34 | * @return void |
||||||
35 | */ |
||||||
36 | public function __construct(Guard $auth, |
||||||
37 | ResponseFactory $response |
||||||
38 | ) { |
||||||
39 | $this->auth = $auth; |
||||||
40 | $this->response = $response; |
||||||
41 | } |
||||||
42 | |||||||
43 | /** |
||||||
44 | * Sets the locale cookie on every request depending |
||||||
45 | * on the locale supplied in the route prefix. |
||||||
46 | * |
||||||
47 | * @param Request $request |
||||||
48 | * @param Closure $next |
||||||
49 | * |
||||||
50 | * @return mixed |
||||||
51 | */ |
||||||
52 | public function handle(Request $request, Closure $next) |
||||||
53 | { |
||||||
54 | if ($this->auth->check()) { |
||||||
55 | $language = (int) $this->auth->user()->language; |
||||||
0 ignored issues
–
show
|
|||||||
56 | } |
||||||
57 | |||||||
58 | if (Cookie::has('locale')) { |
||||||
59 | Config::set('app.locale', Cookie::get('locale')); |
||||||
60 | app()->setLocale(Cookie::get('locale')); |
||||||
0 ignored issues
–
show
The function
app was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
61 | } |
||||||
62 | |||||||
63 | if ($request->session()->has('locale')) { |
||||||
64 | Config::set('app.locale', $request->session()->get('locale')); |
||||||
65 | app()->setLocale($request->session()->get('locale')); |
||||||
66 | } |
||||||
67 | $request->cookies->set('locale', Translation::detectLocale($request)); |
||||||
0 ignored issues
–
show
The method
detectLocale() does not exist on 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
![]() |
|||||||
68 | |||||||
69 | return $next($request); |
||||||
70 | } |
||||||
71 | } |
||||||
72 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths