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

AllowTrait::checkPermission()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 14
ccs 5
cts 6
cp 0.8333
rs 10
cc 2
nc 2
nop 2
crap 2.0185
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