Passed
Push — develop ( 25481c...ab4837 )
by Ngoding
04:42
created

UserPolicy::restore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\User;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
8
class UserPolicy
9
{
10
    use HandlesAuthorization;
11
12
    /**
13
     * Determine whether the user can view any models.
14
     *
15
     * @param  \App\Models\User  $user
16
     * @return \Illuminate\Auth\Access\Response|bool
17
     */
18
    public function viewAny(User $user)
19
    {
20
        return $user->isManager() || $user->isStaff();
21
    }
22
23
    /**
24
     * Determine whether the user can view the model.
25
     *
26
     * @param  \App\Models\User  $user
27
     * @param  \App\Models\User  $model
28
     * @return \Illuminate\Auth\Access\Response|bool
29
     */
30
    public function view(User $user, User $model)
31
    {
32
        return $this->update($user, $model) || $user->is($model);
33
    }
34
35
    /**
36
     * Determine whether the user can create models.
37
     *
38
     * @param  \App\Models\User  $user
39
     * @return \Illuminate\Auth\Access\Response|bool
40
     */
41
    public function create(User $user)
42
    {
43
        return $user->isManager();
44
    }
45
46
    /**
47
     * Determine whether the user can update the model.
48
     *
49
     * @param  \App\Models\User  $user
50
     * @param  \App\Models\User  $model
51
     * @return \Illuminate\Auth\Access\Response|bool
52
     */
53
    public function update(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

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

53
    public function update(User $user, /** @scrutinizer ignore-unused */ User $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        return $this->create($user);
56
    }
57
58
    /**
59
     * Determine whether the user can delete the model.
60
     *
61
     * @param  \App\Models\User  $user
62
     * @param  \App\Models\User  $model
63
     * @return \Illuminate\Auth\Access\Response|bool
64
     */
65
    public function delete(User $user, User $model)
66
    {
67
        if ($user->isAdmin() && $user->is($model)) {
68
            return false;
69
        }
70
71
        return $this->update($user, $model);
72
    }
73
74
    /**
75
     * Determine whether the user can restore the model.
76
     *
77
     * @param  \App\Models\User  $user
78
     * @param  \App\Models\User  $model
79
     * @return \Illuminate\Auth\Access\Response|bool
80
     */
81
    public function restore(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

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

81
    public function restore(User $user, /** @scrutinizer ignore-unused */ User $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        return $user->isAdmin();
84
    }
85
86
    /**
87
     * Determine whether the user can permanently delete the model.
88
     *
89
     * @param  \App\Models\User  $user
90
     * @param  \App\Models\User  $model
91
     * @return \Illuminate\Auth\Access\Response|bool
92
     */
93
    public function forceDelete(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

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

93
    public function forceDelete(User $user, /** @scrutinizer ignore-unused */ User $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95
        return $user->isAdmin();
96
    }
97
}
98