AutorizableMock   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAllowed() 0 14 4
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