UserPolicy::updateRole()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
1
<?php
2
3
namespace App\Policies;
4
5
use App\User;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
8
class UserPolicy
9
{
10
    use HandlesAuthorization;
11
    
12
    /**
13
     * Determine whether the user can view the list of users.
14
     *
15
     * @param  \App\User  $user
16
     * @return mixed
17
     */
18
    public function index(User $user)
19
    {
20
        return $user->isAdmin();
21
    }
22
    
23
    /**
24
     * Determine whether the user can view the create users page.
25
     *
26
     * @param  \App\User  $user
27
     * @return boolean
28
     */
29
    public function create(User $user)
30
    {
31
        return $user->isAdmin();
32
    }
33
    
34
    /**
35
     * Determine whether the user can create a user.
36
     *
37
     * @param  \App\User  $user
38
     * @return boolean
39
     */
40
    public function store(User $user)
41
    {
42
        return $user->isAdmin();
43
    }
44
45
    /**
46
     * Determine whether the user can view the user.
47
     *
48
     * @param  \App\User  $user the current user
49
     * @param  \App\User  $user2 the user to be viewed
50
     * @return boolean
51
     */
52
    public function show(User $user, User $user2)
53
    {
54
        if ($user->isAdmin())
55
            return true;
56
        else
57
            return $user->id === $user2->id;
58
    }
59
    
60
    /**
61
     * Determine whether the user can view the edit page for a user.
62
     *
63
     * @param  \App\User  $user
64
     * @param  \App\User  $user2 the user to be edited
65
     * @return mixed
66
     */
67 View Code Duplication
    public function edit(User $user, User $user2)
68
    {
69
        if ($user->role > $user2->role)
70
        {
71
            return $user->isAdmin();
72
        }
73
        else
74
            return $user->id === $user2->id;
75
    }
76
77
    /**
78
     * Determine whether the user can update themselves or another user.
79
     *
80
     * @param  \App\User  $user
81
     * @param  \App\User  $user2
82
     * @return boolean
83
     */
84 View Code Duplication
    public function update(User $user, User $user2)
85
    {
86
        if ($user->role > $user2->role)
87
        {
88
            return $user->isAdmin();
89
        }
90
        else
91
            return $user->id === $user2->id;
92
    }
93
    
94
    /**
95
     * Determine whether the user can update another user's role.
96
     *
97
     * @param  \App\User  $user
98
     * @param  \App\User  $user2
99
     * @return boolean
100
     */
101
    public function updateRole(User $user, $user2)
102
    {
103
        if ($user->role > $user2->role)
104
        {
105
            return $user->isAdmin();
106
        }
107
        else
108
            return false;
109
    }
110
    
111
    /**
112
     * Determine whether the user can delete the user.
113
     *
114
     * @param  \App\User  $user
115
     * @param  \App\User  $user2
116
     * @return boolean
117
     */
118
    public function destroy(User $user, $user2)
119
    {
120
        if ($user->role > $user2->role)
121
        {
122
            return $user->isAdmin();
123
        }
124
        else
125
            return false;
126
    }
127
    
128
    /**
129
     * Determine whether the user can restore the user.
130
     *
131
     * @param  \App\User  $user
132
     * @return mixed
133
     */
134
    public function restore(User $user)
135
    {
136
        return $user->isAdmin();
137
    }
138
}
139