Conditions | 11 |
Paths | 12 |
Total Lines | 58 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
39 | public function handle($request, Closure $next, $segment = 0) |
||
40 | { |
||
41 | // Ignores all non GET requests: |
||
42 | if ($request->method() !== 'GET') { |
||
43 | return $next($request); |
||
44 | } |
||
45 | |||
46 | $currentUrl = $request->getUri(); |
||
47 | $uriLocale = $this->uriLocalizer->getLocaleFromUrl($currentUrl, $segment); |
||
48 | $defaultLocale = $this->config->get('app.locale'); |
||
49 | |||
50 | // If a locale was set in the url: |
||
51 | if ($uriLocale) { |
||
52 | $currentLanguage = $this->languageRepository->findByLocale($uriLocale); |
||
53 | $selectableLanguages = $this->languageRepository->allExcept($uriLocale); |
||
54 | $altLocalizedUrls = []; |
||
55 | foreach ($selectableLanguages as $lang) { |
||
56 | $altLocalizedUrls[] = [ |
||
57 | 'locale' => $lang->locale, |
||
58 | 'name' => $lang->name, |
||
59 | 'url' => $this->uriLocalizer->localize($currentUrl, $lang->locale, $segment), |
||
60 | ]; |
||
61 | } |
||
62 | |||
63 | // Set app locale |
||
64 | $this->app->setLocale($uriLocale); |
||
65 | |||
66 | // Share language variable with views: |
||
67 | $this->viewFactory->share('currentLanguage', $currentLanguage); |
||
68 | $this->viewFactory->share('selectableLanguages', $selectableLanguages); |
||
69 | $this->viewFactory->share('altLocalizedUrls', $altLocalizedUrls); |
||
70 | |||
71 | // Set locale in session: |
||
72 | if ($request->hasSession() && $request->session()->get('waavi.translation.locale') !== $uriLocale) { |
||
73 | $request->session()->put('waavi.translation.locale', $uriLocale); |
||
74 | } |
||
75 | return $next($request); |
||
76 | } |
||
77 | |||
78 | // If no locale was set in the url, check the session locale |
||
79 | if ($request->hasSession() && $sessionLocale = $request->session()->get('waavi.translation.locale')) { |
||
80 | if ($this->languageRepository->isValidLocale($sessionLocale)) { |
||
81 | return redirect()->to($this->uriLocalizer->localize($currentUrl, $sessionLocale, $segment)); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | // If no locale was set in the url, check the browser's locale: |
||
86 | $browserLocale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); |
||
87 | if ($this->languageRepository->isValidLocale($browserLocale)) { |
||
88 | return redirect()->to($this->uriLocalizer->localize($currentUrl, $browserLocale, $segment)); |
||
89 | } |
||
90 | |||
91 | // If not, redirect to the default locale: |
||
92 | // Keep flash data. |
||
93 | if ($request->hasSession()) { |
||
94 | $request->session()->reflash(); |
||
95 | } |
||
96 | return redirect()->to($this->uriLocalizer->localize($currentUrl, $defaultLocale, $segment)); |
||
97 | } |
||
99 |
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