Thread::getChanger()   A
last analyzed

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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\CommentBundle\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Sulu\Component\Persistence\Model\AuditableInterface;
17
use Sulu\Component\Security\Authentication\UserInterface;
18
19
/**
20
 * Minimum implementation for threads.
21
 */
22
class Thread implements ThreadInterface, AuditableInterface
23
{
24
    /**
25
     * @var int
26
     */
27
    protected $id;
28
29
    /**
30
     * @var string
31
     */
32
    protected $type;
33
34
    /**
35
     * @var string
36
     */
37
    protected $entityId;
38
39
    /**
40
     * @var string
41
     */
42
    protected $title;
43
44
    /**
45
     * @var int
46
     */
47
    protected $commentCount = 0;
48
49
    /**
50
     * @var Collection
51
     */
52
    protected $comments;
53
54
    /**
55
     * @var \DateTime
56
     */
57
    protected $created;
58
59
    /**
60
     * @var \DateTime
61
     */
62
    protected $changed;
63
64
    /**
65
     * @var UserInterface
66
     */
67
    protected $changer;
68
69
    /**
70
     * @var UserInterface
71
     */
72
    protected $creator;
73
74
    /**
75
     * @param string $type
76
     * @param string $entityId
77
     * @param Collection $comments
78
     * @param int $commentCount
79
     */
80 27
    public function __construct($type, $entityId, Collection $comments = null, $commentCount = 0)
81
    {
82 27
        $this->type = $type;
83 27
        $this->entityId = $entityId;
84 27
        $this->comments = $comments ?: new ArrayCollection();
85 27
        $this->commentCount = $commentCount;
86 27
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 8
    public function getId()
92
    {
93 8
        return $this->id;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 10
    public function getType()
100
    {
101 10
        return $this->type;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 10
    public function getEntityId()
108
    {
109 10
        return $this->entityId;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 3
    public function getTitle()
116
    {
117 3
        return $this->title;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 21
    public function setTitle($title)
124
    {
125 21
        $this->title = $title;
126 21
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 11
    public function getCommentCount()
132
    {
133 11
        return $this->commentCount;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139 17
    public function increaseCommentCount()
140
    {
141 17
        ++$this->commentCount;
142
143 17
        return $this;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 6
    public function decreaseCommentCount()
150
    {
151 6
        --$this->commentCount;
152
153 6
        return $this;
154
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159 1
    public function setCommentCount($commentCount)
160
    {
161 1
        $this->commentCount = $commentCount;
162
163 1
        return $this;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 9
    public function getComments()
170
    {
171 9
        return $this->comments;
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177 16
    public function addComment(CommentInterface $comment)
178
    {
179 16
        $this->comments->add($comment);
180 16
        $comment->setThread($this);
181
182 16
        if ($comment->isPublished()) {
183 14
            $this->increaseCommentCount();
184
        }
185
186 16
        return $this;
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192 4
    public function removeComment(CommentInterface $comment)
193
    {
194 4
        $this->comments->removeElement($comment);
195
196 4
        if ($comment->isPublished()) {
197 3
            $this->decreaseCommentCount();
198
        }
199
200 4
        return $this;
201
    }
202
203
    /**
204
     * {@inheritdoc}
205
     */
206
    public function getCreated()
207
    {
208
        return $this->created;
209
    }
210
211
    /**
212
     * {@inheritdoc}
213
     */
214 11
    public function getChanged()
215
    {
216 11
        return $this->changed;
217
    }
218
219
    /**
220
     * {@inheritdoc}
221
     */
222 11
    public function getCreator()
223
    {
224 11
        return $this->creator;
225
    }
226
227
    /**
228
     * {@inheritdoc}
229
     */
230 11
    public function getChanger()
231
    {
232 11
        return $this->changer;
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238 11
    public function getCreatorFullName()
239
    {
240 11
        if (!$this->getCreator()) {
241 11
            return '';
242
        }
243
244
        return $this->getCreator()->getFullName();
245
    }
246
247
    /**
248
     * {@inheritdoc}
249
     */
250 11
    public function getChangerFullName()
251
    {
252 11
        if (!$this->getChanger()) {
253 11
            return '';
254
        }
255
256
        return $this->getChanger()->getFullName();
257
    }
258
}
259