Completed
Push — develop ( 3c99fb...ac15d3 )
by Enea
03:23
created

PermissionEvaluator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 14
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 3 2
A searchOnRoles() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Created on 07/03/18 by enea dhack.
7
 */
8
9
namespace Enea\Authorization\Drivers\Database;
10
11
use Enea\Authorization\Contracts\PermissionsOwner;
12
use Enea\Authorization\Contracts\RolesOwner;
13
14
class PermissionEvaluator extends Evaluator
15
{
16 3
    public function evaluate(PermissionsOwner $owner, array $permissions): bool
17
    {
18 3
        return $this->searchOnRoles($owner, $permissions) || $this->has($owner->permissions()->getQuery())($permissions);
19
    }
20
21 3
    private function searchOnRoles(PermissionsOwner $owner, array $permissions): bool
22
    {
23 3
        if ($owner instanceof RolesOwner) {
24 3
            return $owner->roles()->limit(1)->whereHas('permissions', $this->same($permissions))->exists();
25
        }
26
27
        return false;
28
    }
29
}
30