Issues (7)

src/Http/Controllers/Controller.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace DavideCasiraghi\LaravelQuickMenus\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
    // **********************************************************************
17
18
    /**
19
     * Get the current logged user ID.
20
     * If user is admin or super admin return 0.
21
     *
22
     * @return int $ret
23
     */
24
    public function getLoggedUser()
25
    {
26
        $ret = Auth::user();
27
28
        return $ret;
29
    }
30
31
    // **********************************************************************
32
33
    /**
34
     * Get the current logged user id.
35
     *
36
     * @return bool $ret - the current logged user id, if admin($user->group == 2) or super admin()$user->group == 1) is stet to 0
37
     */
38
    public function getLoggedAuthorId()
39
    {
40
        $user = Auth::user();
41
        $ret = null;
42
        if ($user) {
43
            //$ret = (! $user->isSuperAdmin() && ! $user->isAdmin()) ? $user->id : 0;
44
            $ret = (! $user->group == 1 && ! $user->group == 2) ? $user->id : 0;
0 ignored issues
show
Accessing group on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
45
        }
46
47
        return $ret;
48
    }
49
50
    // **********************************************************************
51
52
    /**
53
     * Get the language name from language code.
54
     *
55
     * @param  string $languageCode
56
     * @return string
57
     */
58 2
    public function getSelectedLocaleName($languageCode)
59
    {
60 2
        $countriesAvailableForTranslations = LaravelLocalization::getSupportedLocales();
61 2
        $ret = $countriesAvailableForTranslations[$languageCode]['name'];
62
63 2
        return $ret;
64
    }
65
}
66