All   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assert() 0 9 3
A getName() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Acl\Assertion;
6
7
use Laminas\Permissions\Acl\Acl;
8
use Laminas\Permissions\Acl\Resource\ResourceInterface;
9
use Laminas\Permissions\Acl\Role\RoleInterface;
10
11
final class All implements NamedAssertion
12
{
13
    /**
14
     * @var NamedAssertion[]
15
     */
16
    private readonly array $asserts;
17
18
    /**
19
     * Check if all asserts are true.
20
     */
21 8
    public function __construct(NamedAssertion ...$asserts)
22
    {
23 8
        $this->asserts = $asserts;
0 ignored issues
show
Bug introduced by
The property asserts is declared read-only in Ecodev\Felix\Acl\Assertion\All.
Loading history...
24
    }
25
26
    /**
27
     * Assert that all given asserts are correct (AND logic).
28
     *
29
     * @param \Ecodev\Felix\Acl\Acl $acl
30
     * @param ?string $privilege
31
     */
32 7
    public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null): bool
33
    {
34 7
        foreach ($this->asserts as $assert) {
35 6
            if (!$assert->assert($acl, $role, $resource, $privilege)) {
36 4
                return false;
37
            }
38
        }
39
40 3
        return true;
41
    }
42
43 1
    public function getName(): string
44
    {
45 1
        return implode(_tr(', et '), array_map(fn ($a) => $a->getName(), $this->asserts));
46
    }
47
}
48