AuthorizationStack   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A addAuthorization() 0 4 1
A isGranted() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Security\Authorization;
6
7
use Chubbyphp\Security\UserInterface;
8
9
final class AuthorizationStack implements AuthorizationInterface
10
{
11
    /**
12
     * @var AuthorizationInterface[]
13
     */
14
    private $authorizations = [];
15
16
    /**
17
     * @param AuthorizationInterface[] $authorizations
18
     */
19 2
    public function __construct(array $authorizations)
20
    {
21 2
        foreach ($authorizations as $authorization) {
22 2
            $this->addAuthorization($authorization);
23
        }
24 2
    }
25
26
    /**
27
     * @param AuthorizationInterface $authorization
28
     */
29 2
    private function addAuthorization(AuthorizationInterface $authorization)
30
    {
31 2
        $this->authorizations[] = $authorization;
32 2
    }
33
34
    /**
35
     * @param UserInterface                  $user
36
     * @param mixed                          $attributes
37
     * @param OwnedByUserModelInterface|null $model
38
     *
39
     * @return bool
40
     */
41 2
    public function isGranted(UserInterface $user, $attributes, OwnedByUserModelInterface $model = null): bool
42
    {
43 2
        foreach ($this->authorizations as $authorization) {
44 2
            if ($authorization->isGranted($user, $attributes, $model)) {
45 2
                return true;
46
            }
47
        }
48
49 1
        return false;
50
    }
51
}
52