Test Setup Failed
Push — master ( 1d88cc...3d481f )
by Alexey
02:54
created

Post::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A Post::getAuthor() 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 Tag[]|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
        $tag->setPost($this);
186
        $this->postTags[] = $tag;
187
188
        return $this;
189
    }
190
191
    public function removePostTag(PostTag $tag): void
192
    {
193
        $this->postTags->removeElement($tag);
194
    }
195
196
    /**
197
     * @return PostTag[]|ArrayCollection
198
     */
199
    public function getPostTags(): iterable
200
    {
201
        return $this->postTags;
202
    }
203
204
    public function setDeleted(bool $deleted): self
205
    {
206
        $this->deleted = $deleted;
207
208
        return $this;
209
    }
210
211
    public function getDeleted(): bool
212
    {
213
        return $this->deleted;
214
    }
215
216
    public function isDeleted(): bool
217
    {
218
        return $this->deleted;
219 1
    }
220
221 1
    public function setPrivate(bool $private): self
222
    {
223
        $this->private = $private;
224
225
        return $this;
226
    }
227
228
    public function isPrivate(): bool
229
    {
230
        return $this->private;
231
    }
232
233
    public function getPrivate(): bool
234
    {
235
        return $this->private;
236
    }
237
238
    public function addComment(Comment $comment): self
239
    {
240
        $this->comments[] = $comment;
241
        $comment->setPost($this);
242
243
        return $this;
244
    }
245
246
    public function removeComment(Comment $comment): void
247
    {
248
        $this->comments->removeElement($comment);
249
    }
250
251
    /**
252
     * @return Comment[]|ArrayCollection
253
     */
254
    public function getComments(): iterable
255
    {
256
        return $this->comments;
257
    }
258
}
259