AutorizableMock::isAllowed()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 1
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\GRBAC\Tests\Mocks;
11
12
use FlexPHP\GRBAC\AutorizableInterface;
13
use FlexPHP\GRBAC\AutorizableTrait;
14
use FlexPHP\GRBAC\RoleInterface;
15
16
final class AutorizableMock implements AutorizableInterface
17
{
18
    use AutorizableTrait;
19
20
    protected function isAllowed(string $slug): bool
21
    {
22
        $deniedPermissions = [];
23
        \array_map(function (RoleInterface $role) use ($slug, &$deniedPermissions): void {
24
            if ($role->has($slug) && $role->allow($slug) === false) {
25
                $deniedPermissions[$slug] = true;
26
            }
27
        }, $this->roles);
28
29
        $permission = \array_filter($this->roles, function (RoleInterface $role) use ($slug, $deniedPermissions) {
30
            return !isset($deniedPermissions[$slug]) && $role->allow($slug);
31
        });
32
33
        return (bool)\count($permission);
34
    }
35
}
36