Test Failed
Pull Request — master (#952)
by Maxim
16:49 queued 07:48
created

CallableRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 12
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A allows() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Security\Rule;
6
7
use Spiral\Security\ActorInterface;
8
use Spiral\Security\RuleInterface;
9
10
/**
11
 * Wraps callable expression.
12
 */
13
final class CallableRule implements RuleInterface
14
{
15
    private \Closure $callable;
16
17 2
    public function __construct(callable $callable)
18
    {
19 2
        $this->callable = $callable(...);
20
    }
21
22 1
    public function allows(ActorInterface $actor, string $permission, array $context): bool
23
    {
24 1
        return (bool) ($this->callable)($actor, $permission, $context);
25
    }
26
}
27