Guardian::getPermissionTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace EmilMoe\Guardian\Support;
4
5
use Illuminate\Support\Facades\Auth;
6
7
/**
8
 * Class Guardian
9
 * @package EmilMoe\Guardian\Guardian\Support
10
 */
11
class Guardian
12
{
13
    /**
14
     * @return mixed
15
     */
16
    public static function getUserTable()
17
    {
18
        return with(self::_getUser())->getTable();
19
    }
20
21
    /**
22
     * @return mixed
23
     */
24
    public static function getUserKey()
25
    {
26
        return with(self::_getUser())->getKeyName();
27
    }
28
29
    /**
30
     * @return bool
31
     */
32
    public static function hasClients()
33
    {
34
        return config('guardian.client') != null;
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public static function getClientTable()
41
    {
42
        return self::_getClient()->getTable();
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public static function getClientKey()
49
    {
50
        return self::_getClient()->getKeyName();
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public static function getClientColumn()
57
    {
58
        return self::getClientTable() .'_'. self::getClientKey();
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    public static function getClientId()
65
    {
66
        return Auth::user()->{config('guardian.client.relation')};
67
68
        foreach (config('guardian.client') as $step)
0 ignored issues
show
Unused Code introduced by
foreach (config('guardia...ser = $user->{$step}; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
69
            $user = $user->{$step};
70
71
        return $user;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public static function getRolesPermissionsTable()
78
    {
79
        return config('guardian.table.role') .'_'. config('guardian.table.permission');
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public static function getUsersRolesTable()
86
    {
87
        return self::getUserTable() .'_'. config('guardian.table.role');
88
    }
89
90
    /**
91
     * @return mixed
92
     */
93
    public static function getUserClass()
94
    {
95
        return config('guardian.user.model');
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public static function getPermissionTable()
102
    {
103
        return config('guardian.table.permission');
104
    }
105
106
    /**
107
     * @return mixed
108
     */
109
    public static function getClientClass()
110
    {
111
        return config('guardian.client.model');
112
    }
113
114
    /**
115
     * @return mixed
116
     */
117
    private static function _getUser()
118
    {
119
        $user = self::getUserClass();
120
        return new $user;
121
    }
122
123
    /**
124
     * @return mixed
125
     */
126
    private static function _getClient()
127
    {
128
        $client = self::getClientClass();
129
        return new $client;
130
    }
131
}