PermissionManagerAbstract::hasAllowedRole()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 8
nop 2
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace App\Auth;
4
5
abstract class PermissionManagerAbstract
6
{
7
    abstract public function __construct(array $settings = []);
8
9
    /**
10
     * @return array|null
11
     */
12
    abstract public function getRolesByOperation($operation);
13
14
    /**
15
     * @return bool
16
     */
17
    public function hasAllowedRole($accountId, $operation)
18
    {
19
        $operationAllowedRoles = $this->getRolesByOperation($operation);
20
        $accountRoles = AuthManager::getAccountManager()->getRole($accountId) ?: [];
21
22
        if ($operationAllowedRoles === null) {
23
            return AuthManager::isDefaultAllow();
24
        }
25
26
        foreach ($accountRoles as $role) {
27
            if (in_array($role, $operationAllowedRoles) === true) {
28
                return true;
29
            }
30
        }
31
32
        return false;
33
    }
34
}
35