PermissionManagerAbstract   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
__construct() 0 1 ?
getRolesByOperation() 0 1 ?
B hasAllowedRole() 0 17 5
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