Completed
Push — master ( 0836e9...dee3ba )
by Park Jong-Hun
03:11
created

PermissionManager::hasAllowedRole()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 8
nop 2
1
<?php
2
3
namespace App\Auth;
4
5
use Prob\Handler\ProcInterface;
6
7
abstract class PermissionManager
8
{
9
    abstract public function __construct($settings = []);
10
11
    /**
12
     * @return array|null
13
     */
14
    abstract public function getRolesByAction($action);
15
16
    /**
17
     * @return bool
18
     */
19 View Code Duplication
    public function hasAllowedRole($accountId, $action)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $actionAllowedRoles = $this->getPermissionItemByAction($action);
0 ignored issues
show
Bug introduced by
The method getPermissionItemByAction() does not seem to exist on object<App\Auth\PermissionManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
        $accountRoles = AuthManager::getAccountManager()->getRole($accountId) ?: [];
23
24
        if ($actionAllowedRoles === null) {
25
            return AuthManager::isDefaultAllow();
26
        }
27
28
        foreach ($accountRoles as $role) {
29
            if (in_array($role, $actionAllowedRoles) === true) {
30
                return true;
31
            }
32
        }
33
34
        return false;
35
    }
36
}
37