Passed
Push — master ( 26152a...8fe73e )
by F
04:04
created

LanguageController::switch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 28
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PWWEB\Localisation\Controllers;
4
5
use App\Http\Controllers\Controller;
1 ignored issue
show
Bug introduced by
The type App\Http\Controllers\Controller 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...
6
use PWWEB\Localisation\Middleware\Locale;
7
use PWWEB\Localisation\Models\Language;
8
9
class LanguageController extends Controller
10
{
11
    /**
12
     * Switch the locale.
13
     *
14
     * @param string $locale Locale that should be switched to
15
     *
16
     * @return \Illuminate\Contracts\Support\Renderable
17
     */
18
    public function switch($locale)
19
    {
20
        $locales = (array) Language::getLocales();
21
22
        // If a locale does not match any of the ones allowed, go back without doing anything.
23
        if (false === in_array($locale, $locales)) {
24
            return redirect()->back();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Contracts\Support\Renderable.
Loading history...
25
        }
26
27
        // Set the right sessions.
28
        session([Locale::SESSION_KEY => $locale]);
29
        app()->setLocale($locale);
0 ignored issues
show
introduced by
The method setLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

29
        app()->/** @scrutinizer ignore-call */ setLocale($locale);
Loading history...
30
        // \LangCountry::setAllSessions($lang_country);
31
32
        // If a user is logged in and it has a lang_country property, set the new lang_country.
33
        /*
34
         * Todo Set language to user options
35
         * if (Auth::user() && array_key_exists('lang_country', Auth::user()->getAttributes())) {
36
         *
37
            try {
38
                \Auth::user()->lang_country = $lang_country;
39
                \Auth::user()->save();
40
            } catch (\Exception $e) {
41
                \Log::error(get_class($this).' at '.__LINE__.': '.$e->getMessage());
42
            }
43
        }*/
44
45
        return redirect()->back();
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Contracts\Support\Renderable.
Loading history...
46
    }
47
}
48