UserPolicy::viewAny()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace  Devpri\Tinre\Policies;
4
5
use Devpri\Tinre\Models\User;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
use Illuminate\Support\Facades\Route;
8
9
class UserPolicy
10
{
11
    use HandlesAuthorization;
12
13 19
    public function viewAny(User $user): bool
14
    {
15 19
        if ($user->hasPermissionTo('user:view:any')) {
16 8
            return true;
17
        }
18
19 11
        return false;
20
    }
21
22 19
    public function view(User $user, User $userModel): bool
23
    {
24 19
        if ($user->hasPermissionTo('user:view:any')) {
25 10
            return true;
26
        }
27
28 9
        if (! $user->hasPermissionTo('user:view')) {
29 1
            return false;
30
        }
31
32 8
        if ($user->id === $userModel->id) {
33 6
            return true;
34
        }
35
36 2
        return false;
37
    }
38
39 13
    public function create(User $user): bool
40
    {
41 13
        if ($user->hasPermissionTo('user:create')) {
42 7
            return true;
43
        }
44
45 6
        return false;
46
    }
47
48 15
    public function update(User $user, User $userModel): bool
49
    {
50 15
        if ($user->id === $userModel->id) {
51 8
            return false;
52
        }
53
54 9
        if ($user->hasPermissionTo('user:update:any')) {
55 6
            return true;
56
        }
57
58 3
        return false;
59
    }
60
61 13
    public function updateOwn(User $user, User $userModel): bool
62
    {
63 13
        if (! $user->hasPermissionTo('user:update')) {
64 1
            return false;
65
        }
66
67 12
        if ($user->id === $userModel->id) {
68 8
            return true;
69
        }
70
71 6
        return false;
72
    }
73
74 12
    public function changeEmail(User $user): bool
75
    {
76 12
        if (! $user->hasPermissionTo('user:change_email')) {
77 1
            return false;
78
        }
79
80 11
        if (Route::has('email.change')) {
81 11
            return true;
82
        }
83
84
        return false;
85
    }
86
87 15
    public function delete(User $user, User $userModel): bool
88
    {
89 15
        if ($user->id === $userModel->id) {
90 7
            return false;
91
        }
92
93 10
        if ($user->hasPermissionTo('user:delete:any')) {
94 7
            return true;
95
        }
96
97 3
        return false;
98
    }
99
}
100