Passed
Push — master ( 02b2dd...8b56d0 )
by Paul
05:11
created

UrlPolicy::update()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

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