Completed
Push — master ( 247d13...46aee1 )
by Zac
13:30 queued 12s
created

TestGroup::hasRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Overwatch\TestBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use FOS\UserBundle\Model\GroupInterface;
7
8
/**
9
 * TestGroup
10
 *
11
 * @ORM\Table()
12
 * @ORM\Entity
13
 * @ORM\HasLifecycleCallbacks
14
 */
15
class TestGroup implements GroupInterface, \JsonSerializable
16
{
17
    /**
18
     * @var integer
19
     *
20
     * @ORM\Column(name="id", type="integer")
21
     * @ORM\Id
22
     * @ORM\GeneratedValue(strategy="AUTO")
23
     */
24
    private $id;
25
26
    /**
27
     * @var string
28
     *
29
     * @ORM\Column(name="name", type="string", length=50, unique=true)
30
     */
31
    private $name;
32
    
33
    /**
34
     * @ORM\OneToMany(targetEntity="Test", mappedBy="group")
35
     */
36
    private $tests;
37
    
38
    /**
39
     * @ORM\ManyToMany(targetEntity="Overwatch\UserBundle\Entity\User", mappedBy="groups")
40
     */
41
    private $users;
42
43
    /**
44
     * @var \DateTime
45
     *
46
     * @ORM\Column(name="created_at", type="datetime")
47
     */
48
    private $createdAt;
49
50
    /**
51
     * @var \DateTime
52
     *
53
     * @ORM\Column(name="updated_at", type="datetime")
54
     */
55
    private $updatedAt;
56
    
57
    
58
    /**
59
     * Constructor
60
     */
61 136
    public function __construct()
62
    {
63 136
        $this->tests = new \Doctrine\Common\Collections\ArrayCollection();
64 136
        $this->users = new \Doctrine\Common\Collections\ArrayCollection();
65 136
    }
66
    
67
    /**
68
     * Serialise object to JSON
69
     */
70 6
    public function jsonSerialize()
71
    {
72
        return [
73 6
            'id'        => $this->getId(),
74 6
            'name'      => $this->getName(),
75 6
            'tests'     => $this->getTests()->toArray(),
76 6
            'users'     => $this->getUsers()->toArray(),
77 6
            'createdAt' => $this->getCreatedAt()->getTimestamp(),
78 6
            'updatedAt' => $this->getUpdatedAt()->getTimestamp()
79 6
        ];
80
    }
81
82
    /**
83
     * Get id
84
     *
85
     * @return integer 
86
     */
87 29
    public function getId()
88
    {
89 29
        return $this->id;
90
    }
91
92
    /**
93
     * Set name
94
     *
95
     * @param string $name
96
     * @return TestGroup
97
     */
98 136
    public function setName($name)
99
    {
100 136
        $this->name = $name;
101
102 136
        return $this;
103
    }
104
105
    /**
106
     * Get name
107
     *
108
     * @return string 
109
     */
110 29
    public function getName()
111
    {
112 29
        return $this->name;
113
    }
114
115
    /**
116
     * Set createdAt
117
     *
118
     * @ORM\PrePersist
119
     * @return TestGroup
120
     */
121 130
    public function setCreatedAt()
122
    {
123 130
        if ($this->createdAt === null) {
124 130
            $this->createdAt = new \DateTime;
125 130
        }
126
        
127 130
        return $this;
128
    }
129
130
    /**
131
     * Get createdAt
132
     *
133
     * @return \DateTime 
134
     */
135 7
    public function getCreatedAt()
136
    {
137 7
        return $this->createdAt;
138
    }
139
140
    /**
141
     * Set updatedAt
142
     *
143
     * @ORM\PrePersist
144
     * @ORM\PreUpdate
145
     * @return TestGroup
146
     */
147 130
    public function setUpdatedAt()
148
    {
149 130
        $this->updatedAt = new \DateTime;
150
151 130
        return $this;
152
    }
153
154
    /**
155
     * Get updatedAt
156
     *
157
     * @return \DateTime 
158
     */
159 6
    public function getUpdatedAt()
160
    {
161 6
        return $this->updatedAt;
162
    }
163
164
    /**
165
     * Add tests
166
     *
167
     * @param \Overwatch\TestBundle\Entity\Test $tests
168
     * @return TestGroup
169
     */
170 1
    public function addTest(\Overwatch\TestBundle\Entity\Test $tests)
171
    {
172 1
        $this->tests[] = $tests;
173
174 1
        return $this;
175
    }
176
177
    /**
178
     * Remove tests
179
     *
180
     * @param \Overwatch\TestBundle\Entity\Test $tests
181
     */
182 1
    public function removeTest(\Overwatch\TestBundle\Entity\Test $tests)
183
    {
184 1
        $this->tests->removeElement($tests);
185 1
    }
186
187
    /**
188
     * Get tests
189
     *
190
     * @return \Doctrine\Common\Collections\Collection 
191
     */
192 11
    public function getTests()
193
    {
194 11
        return $this->tests;
195
    }
196
197
    /**
198
     * Add users
199
     *
200
     * @param \Overwatch\UserBundle\Entity\User $user
201
     * @return TestGroup
202
     */
203 131
    public function addUser(\Overwatch\UserBundle\Entity\User $user)
204
    {
205 131
        $user->addGroup($this);
206 131
        $this->users[] = $user;
207
208 131
        return $this;
209
    }
210
211
    /**
212
     * Remove user
213
     *
214
     * @param \Overwatch\UserBundle\Entity\User $user
215
     */
216 1
    public function removeUser(\Overwatch\UserBundle\Entity\User $user)
217
    {
218 1
        $user->removeGroup($this);
219 1
        $this->users->removeElement($user);
220 1
    }
221
222
    /**
223
     * Get users
224
     *
225
     * @return \Doctrine\Common\Collections\Collection 
226
     */
227 127
    public function getUsers()
228
    {
229 127
        return $this->users;
230
    }
231
    
232
    /**
233
     * FOSUserBundle needs groups to have roles. We don't.
234
     */
235 20
    public function getRoles()
236
    {
237 20
        return [];
238
    }
239 1
    public function setRoles(array $roles)
240
    {
241 1
        return $this;
242
    }
243 1
    public function addRole($role)
244
    {
245 1
        return $this;
246
    }
247 1
    public function removeRole($role)
248
    {
249 1
        return $this;
250
    }
251 1
    public function hasRole($role)
252
    {
253 1
        return false;
254
    }
255
}
256