Passed
Push — master ( 88105a...84be9d )
by Alexey
17:21
created

Post::removePostTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Skobkin\Bundle\PointToolsBundle\Entity\User;
8
9
/**
10
 * Post
11
 *
12
 * @ORM\Table(name="posts", schema="posts", indexes={
13
 *      @ORM\Index(name="idx_post_created_at", columns={"created_at"}),
14
 *      @ORM\Index(name="idx_post_private", columns={"private"}),
15
 * })
16
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
17
 * @ORM\HasLifecycleCallbacks
18
 */
19
class Post
20
{
21
    const TYPE_POST = 'post';
22
    const TYPE_FEED = 'feed';
23
24
    /**
25
     * @var int
26
     *
27
     * @ORM\Column(name="id", type="text")
28
     * @ORM\Id
29
     */
30
    private $id;
31
32
    /**
33
     * @var string
34
     *
35
     * @ORM\Column(name="text", type="text")
36
     */
37
    private $text;
38
39
    /**
40
     * @var \DateTime
41
     *
42
     * @ORM\Column(name="created_at", type="datetime")
43
     */
44
    private $createdAt;
45
46
    /**
47
     * @var \DateTime
48
     *
49
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
50
     */
51
    private $updatedAt;
52
53
    /**
54
     * @var string
55
     *
56
     * @ORM\Column(name="type", type="string", length=6)
57
     */
58
    private $type = self::TYPE_POST;
59
60
    /**
61
     * @var bool
62
     *
63
     * @ORM\Column(name="private", type="boolean", nullable=true)
64
     */
65
    private $private;
66
67
    /**
68
     * @var bool
69
     *
70
     * @ORM\Column(name="is_deleted", type="boolean")
71
     */
72
    private $deleted = false;
73
74
    /**
75
     * @var User
76
     *
77
     * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
78
     * @ORM\JoinColumn(name="author")
79
     */
80
    private $author;
81
82
    /**
83
     * @var File[]|ArrayCollection
84
     *
85
     * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"})
86
     * @ORM\JoinTable(name="posts_files", schema="posts",
87
     *     joinColumns={@ORM\JoinColumn(name="post_id")},
88
     *     inverseJoinColumns={@ORM\JoinColumn(name="file_id")}
89
     * )
90
     */
91
    private $files;
92
93
    /**
94
     * @var Tag[]|ArrayCollection
95
     *
96
     * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag", mappedBy="post", fetch="EXTRA_LAZY", cascade={"persist"}, orphanRemoval=true)
97
     */
98
    private $postTags;
99
100
    /**
101
     * @var Comment[]|ArrayCollection
102
     *
103
     * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", cascade={"persist"})
104
     */
105
    private $comments;
106
107
108
    /**
109
     * Post constructor.
110
     * @param string $id
111
     */
112
    public function __construct($id)
113
    {
114
        $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type integer, but $id is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
115
116
        $this->files = new ArrayCollection();
117
        $this->postTags = new ArrayCollection();
118
        $this->comments = new ArrayCollection();
119
    }
120
121
    /**
122
     * @ORM\PreUpdate
123
     */
124
    public function preUpdate()
125
    {
126
        $this->updatedAt = new \DateTime();
127
    }
128
129
    /**
130
     * Get id
131
     *
132
     * @return integer 
133
     */
134 1
    public function getId()
135
    {
136 1
        return $this->id;
137
    }
138
139
    /**
140
     * Set text
141
     *
142
     * @param string $text
143
     * @return Post
144
     */
145
    public function setText($text)
146
    {
147
        $this->text = $text;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Get text
154
     *
155
     * @return string 
156
     */
157 1
    public function getText()
158
    {
159 1
        return $this->text;
160
    }
161
162
    /**
163
     * Set createdAt
164
     *
165
     * @param \DateTime $createdAt
166
     * @return Post
167
     */
168
    public function setCreatedAt($createdAt)
169
    {
170
        $this->createdAt = $createdAt;
171
172
        return $this;
173
    }
174
175
    /**
176
     * Get createdAt
177
     *
178
     * @return \DateTime 
179
     */
180 1
    public function getCreatedAt()
181
    {
182 1
        return $this->createdAt;
183
    }
184
185
    /**
186
     * @return \DateTime
187
     */
188
    public function getUpdatedAt()
189
    {
190
        return $this->updatedAt;
191
    }
192
193
    /**
194
     * Set type
195
     *
196
     * @param string $type
197
     * @return Post
198
     */
199
    public function setType($type)
200
    {
201
        $this->type = $type;
202
203
        return $this;
204
    }
205
206
    /**
207
     * Get type
208
     *
209
     * @return string 
210
     */
211
    public function getType()
212
    {
213
        return $this->type;
214
    }
215
216
    /**
217
     * @return User
218
     */
219 1
    public function getAuthor()
220
    {
221 1
        return $this->author;
222
    }
223
224
    /**
225
     * @param User $author
226
     * @return Post
227
     */
228
    public function setAuthor($author)
229
    {
230
        $this->author = $author;
231
        return $this;
232
    }
233
234
    /**
235
     * Add files
236
     *
237
     * @param File $files
238
     * @return Post
239
     */
240
    public function addFile(File $files)
241
    {
242
        $this->files[] = $files;
243
244
        return $this;
245
    }
246
247
    /**
248
     * Remove files
249
     *
250
     * @param File $files
251
     */
252
    public function removeFile(File $files)
253
    {
254
        $this->files->removeElement($files);
255
    }
256
257
    /**
258
     * Get files
259
     *
260
     * @return File[]|ArrayCollection
261
     */
262 1
    public function getFiles()
263
    {
264 1
        return $this->files;
265
    }
266
267
    /**
268
     * Add post tags
269
     *
270
     * @param PostTag $tag
271
     * @return Post
272
     */
273
    public function addPostTag(PostTag $tag)
274
    {
275
        $tag->setPost($this);
276
        $this->postTags[] = $tag;
277
278
        return $this;
279
    }
280
281
    /**
282
     * Remove tags
283
     *
284
     * @param PostTag $tag
285
     */
286
    public function removePostTag(PostTag $tag)
287
    {
288
        $this->postTags->removeElement($tag);
289
    }
290
291
    /**
292
     * Get tags
293
     *
294
     * @return PostTag[]|ArrayCollection
295
     */
296 1
    public function getPostTags()
297
    {
298 1
        return $this->postTags;
299
    }
300
301
    /**
302
     * Set deleted
303
     *
304
     * @param boolean $deleted
305
     * @return Post
306
     */
307
    public function setDeleted($deleted)
308
    {
309
        $this->deleted = $deleted;
310
311
        return $this;
312
    }
313
314
    /**
315
     * Get deleted
316
     *
317
     * @return boolean 
318
     */
319
    public function getDeleted()
320
    {
321
        return $this->deleted;
322
    }
323
324
    /**
325
     * Get deleted
326
     *
327
     * @return boolean
328
     */
329
    public function isDeleted()
330
    {
331
        return $this->deleted;
332
    }
333
334
    /**
335
     * Set private
336
     *
337
     * @param boolean $private
338
     * @return Post
339
     */
340
    public function setPrivate($private)
341
    {
342
        $this->private = $private;
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get private
349
     *
350
     * @return boolean
351
     */
352
    public function getPrivate()
353
    {
354
        return $this->private;
355
    }
356
357
    /**
358
     * Add comments
359
     *
360
     * @param Comment $comment
361
     * @return Post
362
     */
363
    public function addComment(Comment $comment)
364
    {
365
        $this->comments[] = $comment;
366
        $comment->setPost($this);
367
368
        return $this;
369
    }
370
371
    /**
372
     * Remove comments
373
     *
374
     * @param Comment $comment
375
     */
376
    public function removeComment(Comment $comment)
377
    {
378
        $this->comments->removeElement($comment);
379
    }
380
381
    /**
382
     * Get comments
383
     *
384
     * @return Comment[]|ArrayCollection
385
     */
386 1
    public function getComments()
387
    {
388 1
        return $this->comments;
389
    }
390
}
391