Passed
Push — dev6 ( d58043...568a9a )
by Ron
17:54
created

AllowTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 2
b 0
f 0
dl 0
loc 16
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkPermission() 0 14 2
1
<?php
2
3
namespace App\Traits;
4
5
use App\Models\User;
6
use App\Models\UserRolePermissions;
7
use Illuminate\Support\Facades\Log;
8
9
/**
10
 *  AllowTrait only has one function to check permission for the policies
11
 */
12
trait AllowTrait
13 76
{
14
    protected function checkPermission(User $user, $description)
15 76
    {
16
        $allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q) use ($description)
17 76
        {
18 76
            $q->where('description', $description);
19
        })->first();
20 76
21
        Log::channel('auth')->debug('User '.$user->username.' is trying to get permission for '.$description.'.  Result - '.$allowed);
22 76
        if($allowed)
23
        {
24
            return $allowed->allow;
25
        }
26
27
        return false;
28
    }
29
}
30