Test Setup Failed
Push — dev6 ( 81193f...01d104 )
by Ron
22:34
created

CustomerPolicy   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 14
c 1
b 0
f 0
dl 0
loc 103
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A forceDelete() 0 2 1
A create() 0 13 2
A viewAny() 0 2 1
A restore() 0 2 1
A delete() 0 2 1
A view() 0 2 1
A update() 0 13 2
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\Customer;
6
use App\Models\User;
7
use App\Models\UserRolePermissions;
8
use Illuminate\Auth\Access\HandlesAuthorization;
9
10
class CustomerPolicy
11
{
12
    use HandlesAuthorization;
13
14
    /**
15
     * Determine whether the user can view any models.
16
     *
17
     * @param  \App\Models\User  $user
18
     * @return mixed
19
     */
20
    public function viewAny(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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

20
    public function viewAny(/** @scrutinizer ignore-unused */ User $user)

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...
21
    {
22
        //
23
    }
24
25
    /**
26
     * Determine whether the user can view the model.
27
     *
28
     * @param  \App\Models\User  $user
29
     * @param  \App\Models\Customer  $customer
30
     * @return mixed
31
     */
32
    public function view(User $user, Customer $customer)
0 ignored issues
show
Unused Code introduced by
The parameter $customer 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

32
    public function view(User $user, /** @scrutinizer ignore-unused */ Customer $customer)

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...
Unused Code introduced by
The parameter $user 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

32
    public function view(/** @scrutinizer ignore-unused */ User $user, Customer $customer)

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...
33
    {
34
        //
35
    }
36
37
    /**
38
     * Determine whether the user can create models.
39
     *
40
     * @param  \App\Models\User  $user
41
     * @return mixed
42
     */
43
    public function create(User $user)
44
    {
45
        $allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q)
46
        {
47
            $q->where('description', 'Add Customer');
48
        })->first();
49
50
        if($allowed)
51
        {
52
            return $allowed->allow;
53
        }
54
55
        return false;
56
    }
57
58
    /**
59
     * Determine whether the user can update the model.
60
     *
61
     * @param  \App\Models\User  $user
62
     * @param  \App\Models\Customer  $customer
63
     * @return mixed
64
     */
65
    public function update(User $user, Customer $customer)
0 ignored issues
show
Unused Code introduced by
The parameter $customer 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

65
    public function update(User $user, /** @scrutinizer ignore-unused */ Customer $customer)

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...
66
    {
67
        $allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q)
68
        {
69
            $q->where('description', 'Update Customer');
70
        })->first();
71
72
        if($allowed)
73
        {
74
            return $allowed->allow;
75
        }
76
77
        return false;
78
    }
79
80
    /**
81
     * Determine whether the user can delete the model.
82
     *
83
     * @param  \App\Models\User  $user
84
     * @param  \App\Models\Customer  $customer
85
     * @return mixed
86
     */
87
    public function delete(User $user, Customer $customer)
0 ignored issues
show
Unused Code introduced by
The parameter $customer 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

87
    public function delete(User $user, /** @scrutinizer ignore-unused */ Customer $customer)

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...
Unused Code introduced by
The parameter $user 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

87
    public function delete(/** @scrutinizer ignore-unused */ User $user, Customer $customer)

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...
88
    {
89
        //
90
    }
91
92
    /**
93
     * Determine whether the user can restore the model.
94
     *
95
     * @param  \App\Models\User  $user
96
     * @param  \App\Models\Customer  $customer
97
     * @return mixed
98
     */
99
    public function restore(User $user, Customer $customer)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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

99
    public function restore(/** @scrutinizer ignore-unused */ User $user, Customer $customer)

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...
Unused Code introduced by
The parameter $customer 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

99
    public function restore(User $user, /** @scrutinizer ignore-unused */ Customer $customer)

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...
100
    {
101
        //
102
    }
103
104
    /**
105
     * Determine whether the user can permanently delete the model.
106
     *
107
     * @param  \App\Models\User  $user
108
     * @param  \App\Models\Customer  $customer
109
     * @return mixed
110
     */
111
    public function forceDelete(User $user, Customer $customer)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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

111
    public function forceDelete(/** @scrutinizer ignore-unused */ User $user, Customer $customer)

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...
Unused Code introduced by
The parameter $customer 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

111
    public function forceDelete(User $user, /** @scrutinizer ignore-unused */ Customer $customer)

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...
112
    {
113
        //
114
    }
115
}
116