RightsRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A get() 0 8 2
1
<?php
2
3
namespace Mouf\Security\Rights;
4
5
use Mouf\Security\RightsService\RightInterface;
6
7
/**
8
 * This class registers all available rights in Mouf.
9
 */
10
class RightsRegistry
11
{
12
    /**
13
     * The list of all supported rights in the application, indexed by right name.
14
     *
15
     * @var RightInterface[]
16
     */
17
    protected $rights;
18
19
    /**
20
     * @param RightInterface[] $rights The list of all supported rights in the application.
21
     */
22
    public function __construct(array $rights)
23
    {
24
        $this->rights = [];
25
        foreach ($rights as $right) {
26
            $this->rights[$right->getName()] = $right;
27
        }
28
    }
29
30
    /**
31
     * Returns a right by name.
32
     *
33
     * @param string $name
34
     *
35
     * @return RightInterface
36
     *
37
     * @throws NotFoundException
38
     */
39
    public function get(string $name) : RightInterface
40
    {
41
        if (!isset($this->rights[$name])) {
42
            throw NotFoundException::create($name);
43
        }
44
45
        return $this->rights[$name];
46
    }
47
}
48