Completed
Push — Recipes ( 630f49...c8afb0 )
by Laurent
12:15 queued 03:48
created

Group   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getUsers() 0 4 1
A addUser() 0 6 1
A hasRole() 0 10 2
A removeUser() 0 4 1
A __toString() 0 4 1
1
<?php
2
/**
3
 * Entity Group.
4
 *
5
 * PHP Version 7
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: <git_id>
12
 *
13
 * @link https://github.com/Dev-Int/glsr
14
 */
15
namespace  App\Entity\Staff;
16
17
use FOS\UserBundle\Model\Group as BaseGroup;
18
use App\Entity\Staff\User;
19
use Doctrine\ORM\Mapping as ORM;
20
21
/**
22
 * Group Entity.
23
 *
24
 * @category Entity
25
 *
26
 * @ORM\Entity
27
 * @ORM\Entity(repositoryClass="App\Repository\Staff\GroupRepository")
28
 * @ORM\Table(name="fos_group")
29
 */
30
class Group extends BaseGroup
31
{
32
    /**
33
     * @var int $grpId Group id
34
     *
35
     * @ORM\Id
36
     * @ORM\Column(name="id", type="integer")
37
     * @ORM\GeneratedValue(strategy="AUTO")
38
     */
39
    protected $grpId;
40
41
    /**
42
     * @var string
43
     */
44
    protected $name;
45
46
    /**
47
     * @var array
48
     */
49
    protected $roles;
50
51
    /**
52
     * @var array $users Array of users
53
     * @ORM\ManyToMany(targetEntity="App\Entity\Staff\User", mappedBy="groups")
54
     */
55
    protected $users;
56
57
    /**
58
     * Get id.
59
     *
60
     * @return int
61
     */
62
    public function getId()
63
    {
64
        return $this->grpId;
65
    }
66
67
    /**
68
     * Get Users
69
     *
70
     * @return  App\Entity\Staff\User
71
     */
72
    public function getUsers()
73
    {
74
        return $this->users;
75
    }
76
77
    /**
78
     * Add users
79
     *
80
     * @param \App\Entity\Staff\User $users
81
     * @return Group
82
     */
83
    public function addUser(User $users)
84
    {
85
        $this->users[] = $users;
86
87
        return $this;
88
    }
89
90
    public function hasRole($role)
91
    {
92
        if (is_array($this->roles)) {
93
            $return = in_array(strtoupper($role), $this->roles, true);
94
        } else {
95
            $return = false;
96
        }
97
98
        return $return;
99
    }
100
101
    /**
102
     * Remove users
103
     *
104
     * @param \App\Entity\Staff\User $users
105
     */
106
    public function removeUser(User $users)
107
    {
108
        $this->users->removeElement($users);
0 ignored issues
show
Bug introduced by
The method removeElement cannot be called on $this->users (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
109
    }
110
111
    /**
112
     * This method allows to do "echo $group".
113
     * <p> So, to "show" $group,
114
     * PHP will actually show the return of this method. <br />
115
     * Here, the name, so "echo $group"
116
     * is equivalent to "echo $unit->getName()" </ p>.
117
     * @return string name
118
     */
119
    public function __toString()
120
    {
121
        return $this->getName();
122
    }
123
}
124