TenantUser::addRole()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Tahoe\Bundle\MultiTenancyBundle\Entity;
4
5
/**
6
 * TenantUser
7
 */
8
class TenantUser
9
{
10
    const ROLE_TENANT_MANAGER = 'ROLE_TENANT_MANAGER';
11
    const ROLE_TENANT_CUSTOMER = 'ROLE_TENANT_CUSTOMER';
12
13
    /**
14
     * @var Tenant $tenant
15
     */
16
    protected $tenant;
17
18
    /**
19
     * @var User $user
20
     */
21
    protected $user;
22
23
    /**
24
     * @var array $roles
25
     */
26
    protected $roles;
27
28
    public function __construct()
29
    {
30
        $this->roles = array(); // must be an array NOT ArrayCollection
31
    }
32
33
    /**
34
     * @param array $roles
35
     *
36
     * @return $this
37
     */
38
    public function setRoles($roles)
39
    {
40
        $this->roles = $roles;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getRoles()
49
    {
50
        return $this->roles;
51
    }
52
53
    /**
54
     * Available role constants:
55
     * - TenantUser::ROLE_TENANT_MANAGER
56
     * - TenantUser::ROLE_TENANT_CUSTOMER
57
     *
58
     * @param string $role
59
     * @return $this
60
     */
61
    public function addRole($role)
62
    {
63
        $role = strtoupper($role);
64
65
        if (!in_array($role, $this->roles, true)) {
66
            $this->roles[] = $role;
67
        }
68
69
        return $this;
70
    }
71
72
    /**
73
     * @param string $role
74
     *
75
     * @return $this
76
     */
77
    public function removeRole($role)
78
    {
79
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
80
            unset($this->roles[$key]);
81
            $this->roles = array_values($this->roles);
82
        }
83
84
        return $this;
85
    }
86
87
    /**
88
     * @param string $role
89
     *
90
     * @return boolean
91
     */
92
    public function hasRole($role)
93
    {
94
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
95
            return true;
96
        }
97
98
        return false;
99
    }
100
101
    /**
102
     * @param \Tahoe\Bundle\MultiTenancyBundle\Model\MultiTenantUserInterface $user
103
     *
104
     * @return $this
105
     */
106
    public function setUser($user)
107
    {
108
        $this->user = $user;
0 ignored issues
show
Documentation Bug introduced by
It seems like $user of type object<Tahoe\Bundle\Mult...ltiTenantUserInterface> is incompatible with the declared type object<Tahoe\Bundle\Mult...ancyBundle\Entity\User> of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return \Tahoe\Bundle\MultiTenancyBundle\Model\MultiTenantUserInterface
115
     */
116
    public function getUser()
117
    {
118
        return $this->user;
119
    }
120
121
    /**
122
     * @param \Tahoe\Bundle\MultiTenancyBundle\Entity\Tenant $tenant
123
     *
124
     * @return $this
125
     */
126
    public function setTenant($tenant)
127
    {
128
        $this->tenant = $tenant;
129
130
        return $this;
131
    }
132
133
    /**
134
     * @return \Tahoe\Bundle\MultiTenancyBundle\Entity\Tenant
135
     */
136
    public function getTenant()
137
    {
138
        return $this->tenant;
139
    }
140
}
141