Controller::getSelectedLocaleName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
nc 1
nop 1
cc 1
crap 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelTestimonials\Http\Controllers;
4
5
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6
use Illuminate\Foundation\Bus\DispatchesJobs;
7
use Illuminate\Foundation\Validation\ValidatesRequests;
8
use Illuminate\Routing\Controller as BaseController;
9
use Illuminate\Support\Facades\Auth;
10
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
11
12
class Controller extends BaseController
13
{
14
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
15
16
    // https://stackoverflow.com/questions/51611015/authuser-return-null-5-6
17 14
    public function __construct()
18
    {
19
        $this->middleware(function ($request, $next) {
20 14
            $this->user = Auth::user();
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
22 14
            return $next($request);
23 14
        });
24 14
    }
25
26
    // **********************************************************************
27
28
    /**
29
     * Get the language name from language code.
30
     *
31
     * @param  string $languageCode
32
     * @return string
33
     */
34 4
    public function getSelectedLocaleName($languageCode)
35
    {
36 4
        $countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales();
37 4
        $ret = $countriesAvailableForTranslations[$languageCode]['name'];
38
39 4
        return $ret;
40
    }
41
}
42