Test Failed
Push — master ( 49ed34...5345eb )
by Elijah
03:06
created

RoleManager::isPermissionInRoles()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the EloyekunlePermissionsBundle package.
5
 *
6
 * (c) Elijah Oyekunle <https://elijahoyekunle.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Eloyekunle\PermissionsBundle\Model;
13
14
abstract class RoleManager implements RoleManagerInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function createRole()
20
    {
21
        $class = $this->getClass();
22
        $role = new $class();
23
24
        return $role;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function isPermissionInRoles($permission, array $roles)
31
    {
32
        $hasPermission = false;
33
34
        foreach ($roles as $roleName) {
35
            /** @var \Eloyekunle\PermissionsBundle\Model\Role $role */
36
            $role = $this->findRoleBy(['name' => $roleName]);
37
38
            if ($role->isSuperAdmin() || $role->hasPermission($permission)) {
39
                $hasPermission = true;
40
                break;
41
            }
42
        }
43
44
        return $hasPermission;
45
    }
46
}
47