Completed
Branch feature/pre-split (197e7e)
by Anton
03:26
created

CallableRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 10
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A allows() 0 4 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Security\Rules;
9
10
use Spiral\Security\ActorInterface;
11
use Spiral\Security\RuleInterface;
12
13
/**
14
 * Wraps callable expression.
15
 */
16
class CallableRule implements RuleInterface
17
{
18
    /**
19
     * @var callable
20
     */
21
    private $callable = null;
22
23
    /**
24
     * @param callable $callable
25
     */
26
    public function __construct(callable $callable)
27
    {
28
        $this->callable = $callable;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function allows(ActorInterface $actor, string $permission, array $context): bool
35
    {
36
        return (bool)call_user_func($this->callable, $actor, $permission, $context);
37
    }
38
}