Completed
Push — master ( 4407aa...f0730d )
by ANTHONIUS
22s queued 14s
created

Group   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 104
ccs 23
cts 26
cp 0.8846
rs 10
c 0
b 0
f 0
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 3 1
A removeRole() 0 8 2
A setRoles() 0 5 1
A getId() 0 3 1
A addRole() 0 7 2
A hasRole() 0 3 1
A setName() 0 5 1
A getRoles() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\Model;
15
16
/**
17
 * Base group.
18
 *
19
 * @author Anthonius Munthi <[email protected]>
20
 */
21
abstract class Group implements GroupInterface
22
{
23
    /**
24
     * @var mixed
25
     */
26
    protected $id;
27
28
    /**
29
     * @var string
30
     */
31
    protected $name;
32
33
    /**
34
     * @var array
35
     */
36
    protected $roles;
37
38
    /**
39
     * Group constructor.
40
     *
41
     * @param string $name
42
     * @param array  $roles
43
     */
44 13
    public function __construct($name, $roles = [])
45
    {
46 13
        $this->name  = $name;
47 13
        $this->roles = $roles;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 5
    public function addRole($role)
54
    {
55 5
        if (!$this->hasRole($role)) {
56 5
            $this->roles[] = strtoupper($role);
57
        }
58
59 5
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 6
    public function getId()
66
    {
67 6
        return $this->id;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 6
    public function getName()
74
    {
75 6
        return $this->name;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 5
    public function hasRole($role)
82
    {
83 5
        return \in_array(strtoupper($role), $this->roles, true);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 6
    public function getRoles()
90
    {
91 6
        return $this->roles;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 2
    public function removeRole($role)
98
    {
99 2
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
100 2
            unset($this->roles[$key]);
101 2
            $this->roles = array_values($this->roles);
102
        }
103
104 2
        return $this;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 5
    public function setName($name)
111
    {
112 5
        $this->name = $name;
113
114 5
        return $this;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function setRoles(array $roles)
121
    {
122
        $this->roles = $roles;
123
124
        return $this;
125
    }
126
}
127