Failed Conditions
Push — master ( cdc595...f2bb18 )
by Adrien
02:12
created

All::assert()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 12
rs 10
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\Assertion\AssertionInterface;
9
use Laminas\Permissions\Acl\Resource\ResourceInterface;
10
use Laminas\Permissions\Acl\Role\RoleInterface;
11
12
class All implements AssertionInterface
13
{
14
    /**
15
     * @var AssertionInterface[]
16
     */
17
    private $asserts;
18
19
    /**
20
     * Check if all asserts are true
21
     *
22
     * @param AssertionInterface ...$asserts
23
     */
24
    public function __construct(AssertionInterface ...$asserts)
25
    {
26
        $this->asserts = $asserts;
27
    }
28
29
    /**
30
     * Assert that all given assert are correct (AND logic)
31
     *
32
     * @param \Ecodev\Felix\Acl\Acl $acl
33
     * @param RoleInterface $role
34
     * @param ResourceInterface $resource
35
     * @param string $privilege
36
     *
37
     * @return bool
38
     */
39
    public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
40
    {
41
        foreach ($this->asserts as $assert) {
42
            if (!$assert->assert($acl, $role, $resource, $privilege)) {
43
                return false;
44
            }
45
        }
46
47
        return true;
48
    }
49
}
50