HasPermissionsTrait::hasRole()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Permissions;
5
6
use App\Models\Security_group_user;
7
8
trait HasPermissionsTrait
9
{
10
    public function roles(){
11
        return $this->belongsToMany(Security_group_user::class,'security_group_users');
0 ignored issues
show
Bug introduced by
It seems like belongsToMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        return $this->/** @scrutinizer ignore-call */ belongsToMany(Security_group_user::class,'security_group_users');
Loading history...
12
    }
13
14
15
    public function hasRole( ... $roles ) {
16
        foreach ($roles as $role) {
17
            if ($this->roles->contains('code', $role)) {
18
                return true;
19
            }
20
        }
21
        return false;
22
    }
23
24
25
}