Passed
Push — dev6 ( 1762ad...6b002f )
by Ron
08:16
created

EquipmentCategoryPolicy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 0 12 3
A delete() 0 3 1
A create() 0 3 1
A update() 0 3 1
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\EquipmentCategory;
6
use App\Models\User;
7
use App\Models\UserRolePermissions;
8
use Illuminate\Auth\Access\HandlesAuthorization;
9
use Illuminate\Support\Facades\Log;
10
11
class EquipmentCategoryPolicy
12
{
13
    use HandlesAuthorization;
14
15
    /*
16
    *   Allow anyone with "Manage Equipment" permission
17
    */
18 13
    public function before(User $user, $method)
19
    {
20 13
        $allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q)
21
        {
22 13
            $q->where('description', 'Manage Equipment');
23 13
        })->first();
24
25 13
        Log::channel('auth')->debug('User '.$user->username.' is checking User Policy access to '.$method.'.  Result - '.($allowed->allow ? 'Allow' : 'Deny'));
26
27 13
        if($allowed->allow)
28
        {
29 7
            return $allowed->allow;
30
        }
31 6
    }
32
33
        /**
34
     * Determine whether the user can create models.
35
     *
36
     * @param  \App\Models\User  $user
37
     * @return mixed
38
     */
39 4
    public function create(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

39
    public function create(/** @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...
40
    {
41 4
        return false;
42
    }
43
44
    /**
45
     * Determine whether the user can update the model.
46
     *
47
     * @param  \App\Models\User  $user
48
     * @param  \App\Models\EquipmentCategory  $equipmentCategory
49
     * @return mixed
50
     */
51 1
    public function update(User $user, EquipmentCategory $equipmentCategory)
0 ignored issues
show
Unused Code introduced by
The parameter $equipmentCategory 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

51
    public function update(User $user, /** @scrutinizer ignore-unused */ EquipmentCategory $equipmentCategory)

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

51
    public function update(/** @scrutinizer ignore-unused */ User $user, EquipmentCategory $equipmentCategory)

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...
52
    {
53 1
        return false;
54
    }
55
56
    /**
57
     * Determine whether the user can delete the model.
58
     *
59
     * @param  \App\Models\User  $user
60
     * @param  \App\Models\EquipmentCategory  $equipmentCategory
61
     * @return mixed
62
     */
63 1
    public function delete(User $user, EquipmentCategory $equipmentCategory)
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

63
    public function delete(/** @scrutinizer ignore-unused */ User $user, EquipmentCategory $equipmentCategory)

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 $equipmentCategory 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

63
    public function delete(User $user, /** @scrutinizer ignore-unused */ EquipmentCategory $equipmentCategory)

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...
64
    {
65 1
        return false;
66
    }
67
}
68