Post   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 241
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 2

Test Coverage

Coverage 20.51%

Importance

Changes 0
Metric Value
wmc 24
lcom 4
cbo 2
dl 0
loc 241
ccs 8
cts 39
cp 0.2051
rs 10
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A preUpdate() 0 4 1
A getId() 0 4 1
A setText() 0 6 1
A getText() 0 4 1
A getCreatedAt() 0 4 1
A getUpdatedAt() 0 4 1
A getType() 0 4 1
A getAuthor() 0 4 1
A addFile() 0 6 1
A removeFile() 0 4 1
A getFiles() 0 4 1
A addPostTag() 0 6 1
A removePostTag() 0 4 1
A getPostTags() 0 4 1
A setDeleted() 0 6 1
A getDeleted() 0 4 1
A isDeleted() 0 4 1
A setPrivate() 0 6 1
A isPrivate() 0 4 1
A getPrivate() 0 4 1
A addComment() 0 7 1
A removeComment() 0 4 1
A getComments() 0 4 1
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
 * @ORM\Table(name="posts", schema="posts", indexes={
11
 *      @ORM\Index(name="idx_post_created_at", columns={"created_at"}),
12
 *      @ORM\Index(name="idx_post_private", columns={"private"}),
13
 * })
14
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository")
15
 * @ORM\HasLifecycleCallbacks
16
 */
17
class Post
18
{
19
    public const TYPE_POST = 'post';
20
    public const TYPE_FEED = 'feed';
21
22
    /**
23
     * @var string
24
     *
25
     * @ORM\Column(name="id", type="text")
26
     * @ORM\Id
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(name="text", type="text")
34
     */
35
    private $text;
36
37
    /**
38
     * @var \DateTime
39
     *
40
     * @ORM\Column(name="created_at", type="datetime")
41
     */
42
    private $createdAt;
43
44
    /**
45
     * @var \DateTime
46
     *
47
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
48
     */
49
    private $updatedAt;
50
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(name="type", type="string", length=6)
55
     */
56
    private $type = self::TYPE_POST;
57
58
    /**
59
     * @var bool
60
     *
61
     * @ORM\Column(name="private", type="boolean", nullable=true)
62
     */
63
    private $private;
64
65
    /**
66
     * @var bool
67
     *
68
     * @ORM\Column(name="is_deleted", type="boolean")
69
     */
70
    private $deleted = false;
71
72
    /**
73
     * @var User
74
     *
75
     * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
76
     * @ORM\JoinColumn(name="author")
77
     */
78
    private $author;
79
80
    /**
81
     * @var File[]|ArrayCollection
82
     *
83
     * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File", fetch="EXTRA_LAZY", cascade={"persist"})
84
     * @ORM\JoinTable(name="posts_files", schema="posts",
85
     *     joinColumns={@ORM\JoinColumn(name="post_id")},
86
     *     inverseJoinColumns={@ORM\JoinColumn(name="file_id")}
87
     * )
88
     */
89
    private $files;
90
91
    /**
92
     * @var PostTag[]|ArrayCollection
93
     *
94
     * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostTag", mappedBy="post", fetch="EXTRA_LAZY", cascade={"persist"}, orphanRemoval=true)
95
     */
96
    private $postTags;
97
98
    /**
99
     * @var Comment[]|ArrayCollection
100
     *
101
     * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", cascade={"persist"})
102
     */
103
    private $comments;
104
105
106
    public function __construct(string $id, User $author, \DateTime $createdAt, string $type)
107
    {
108
        $this->id = $id;
109
        $this->author = $author;
110
        $this->createdAt = $createdAt;
111
        $this->type = $type;
112
113
        $this->files = new ArrayCollection();
114
        $this->postTags = new ArrayCollection();
115
        $this->comments = new ArrayCollection();
116
    }
117
118
    /**
119
     * @ORM\PreUpdate
120
     */
121
    public function preUpdate(): void
122
    {
123
        $this->updatedAt = new \DateTime();
124
    }
125
126
    public function getId(): string
127
    {
128
        return $this->id;
129
    }
130
131
    public function setText(string $text): self
132
    {
133
        $this->text = $text;
134 1
135
        return $this;
136 1
    }
137
138
    public function getText(): string
139
    {
140
        return $this->text;
141
    }
142
143
    public function getCreatedAt(): \DateTime
144
    {
145
        return $this->createdAt;
146
    }
147
148
    public function getUpdatedAt(): ?\DateTime
149
    {
150
        return $this->updatedAt;
151
    }
152
153
    public function getType(): string
154
    {
155
        return $this->type;
156
    }
157 1
158
    public function getAuthor(): User
159 1
    {
160
        return $this->author;
161
    }
162
163
    public function addFile(File $files): self
164
    {
165
        $this->files[] = $files;
166
167
        return $this;
168
    }
169
170
    public function removeFile(File $files): void
171
    {
172
        $this->files->removeElement($files);
173
    }
174
175
    /**
176
     * @return File[]|ArrayCollection
177
     */
178
    public function getFiles(): iterable
179
    {
180 1
        return $this->files;
181
    }
182 1
183
    public function addPostTag(PostTag $tag): self
184
    {
185
        $this->postTags[] = $tag;
186
187
        return $this;
188
    }
189
190
    public function removePostTag(PostTag $tag): void
191
    {
192
        $this->postTags->removeElement($tag);
193
    }
194
195
    /**
196
     * @return PostTag[]|ArrayCollection
197
     */
198
    public function getPostTags(): iterable
199
    {
200
        return $this->postTags;
201
    }
202
203
    public function setDeleted(bool $deleted): self
204
    {
205
        $this->deleted = $deleted;
206
207
        return $this;
208
    }
209
210
    public function getDeleted(): bool
211
    {
212
        return $this->deleted;
213
    }
214
215
    public function isDeleted(): bool
216
    {
217
        return $this->deleted;
218
    }
219 1
220
    public function setPrivate(bool $private): self
221 1
    {
222
        $this->private = $private;
223
224
        return $this;
225
    }
226
227
    public function isPrivate(): bool
228
    {
229
        return $this->private;
230
    }
231
232
    public function getPrivate(): bool
233
    {
234
        return $this->private;
235
    }
236
237
    public function addComment(Comment $comment): self
238
    {
239
        $this->comments[] = $comment;
240
        $comment->setPost($this);
241
242
        return $this;
243
    }
244
245
    public function removeComment(Comment $comment): void
246
    {
247
        $this->comments->removeElement($comment);
248
    }
249
250
    /**
251
     * @return Comment[]|ArrayCollection
252
     */
253
    public function getComments(): iterable
254
    {
255
        return $this->comments;
256
    }
257
}
258