Role   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 93
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addParent() 0 5 1
A hasParents() 0 3 1
A children() 0 3 1
A addChildren() 0 5 1
A removeChildren() 0 5 1
A parents() 0 3 1
A removeParent() 0 5 1
A __toString() 0 3 1
1
<?php
2
3
namespace Tleckie\Acl;
4
5
use Tleckie\Acl\Role\RoleInterface;
6
7
/**
8
 * Class Role
9
 *
10
 * @package Tleckie\Acl
11
 * @author  Teodoro Leckie Westberg <[email protected]>
12
 */
13
class Role implements RoleInterface
14
{
15
    /** @var string */
16
    private string $id;
17
18
    /** @var RoleInterface[] */
19
    private array $parents;
20
21
    /** @var RoleInterface[] */
22
    private array $children;
23
24
    /**
25
     * Role constructor.
26
     *
27
     * @param string $id
28
     */
29
    public function __construct(string $id)
30
    {
31
        $this->id = $id;
32
        $this->parents = [];
33
        $this->children = [];
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function __toString(): string
40
    {
41
        return $this->id;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function addParent(RoleInterface $role): RoleInterface
48
    {
49
        $this->parents[(string)$role] = $role;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function removeParent(RoleInterface $role): RoleInterface
58
    {
59
        unset($this->parents[(string)$role]);
60
61
        return $this;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67
    public function parents(): array
68
    {
69
        return $this->parents;
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function hasParents(): bool
76
    {
77
        return !empty($this->parents);
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83
    public function addChildren(RoleInterface $role): RoleInterface
84
    {
85
        $this->children[(string)$role] = $role;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93
    public function removeChildren(RoleInterface $role): RoleInterface
94
    {
95
        unset($this->children[(string)$role]);
96
97
        return $this;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function children(): array
104
    {
105
        return $this->children;
106
    }
107
}
108