Passed
Pull Request — master (#49)
by
unknown
14:38
created

Post::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Entity;
4
5
use Cycle\Annotated\Annotation\Column;
6
use Cycle\Annotated\Annotation\Entity;
7
use Cycle\Annotated\Annotation\Relation\BelongsTo;
8
use Cycle\Annotated\Annotation\Relation\HasMany;
9
use Cycle\Annotated\Annotation\Relation\ManyToMany;
10
use Cycle\Annotated\Annotation\Table;
11
use Cycle\Annotated\Annotation\Table\Index;
12
use Cycle\ORM\Relation\Pivoted\PivotedCollection;
13
use DateTimeImmutable;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Yiisoft\Security\Random;
16
17
/**
18
 * @Entity(
19
 *     repository="App\Repository\PostRepository",
20
 *     mapper="App\Mapper\PostMapper",
21
 *     constrain="App\Constrain\PostPublic"
22
 * )
23
 * @Table(
24
 *     indexes={
25
 *         @Index(columns={"public","publishedAt"}),
26
 *     }
27
 * )
28
 */
29
class Post
30
{
31
    /**
32
     * @Column(type="primary")
33
     * @var int
34
     */
35
    private $id;
36
37
    /**
38
     * @Column(type="string(128)")
39
     * @var string
40
     */
41
    private $slug;
42
43
    /**
44
     * @Column(type="string(255)")
45
     * @var string
46
     */
47
    private $title;
48
49
    /**
50
     * @Column(type="bool", default="false")
51
     * @var bool
52
     */
53
    private $public;
54
55
    /**
56
     * @Column(type="text")
57
     * @var string
58
     */
59
    private $content;
60
61
    /**
62
     * @Column(type="datetime")
63
     * @var DateTimeImmutable
64
     */
65
    private $createdAt;
66
67
    /**
68
     * @Column(type="datetime")
69
     * @var DateTimeImmutable
70
     */
71
    private $updatedAt;
72
73
    /**
74
     * @Column(type="datetime", nullable=true)
75
     * @var DateTimeImmutable|null
76
     */
77
    private $publishedAt;
78
79
    /**
80
     * @Column(type="datetime", nullable=true)
81
     * @var DateTimeImmutable|null
82
     */
83
    private $deletedAt;
84
85
    /**
86
     * @BelongsTo(target="App\Entity\User", nullable=false)
87
     * @var User|\Cycle\ORM\Promise\Reference
88
     */
89
    private $user;
90
91
    /**
92
     * @ManyToMany(target="App\Entity\Tag", though="PostTag", fkAction="CASCADE")
93
     * @var PivotedCollection
94
     */
95
    private $tags;
96
97
    /**
98
     * @HasMany(target="App\Entity\Comment")
99
     * @var ArrayCollection
100
     */
101
    private $comments;
102
103
    public function __construct()
104
    {
105
        $this->tags = new PivotedCollection();
106
        $this->comments = new ArrayCollection();
107
        if (!isset($this->slug)) {
108
            $this->resetSlug();
109
        }
110
    }
111
112
    public function getId(): ?string
113
    {
114
        return $this->id;
115
    }
116
117
    public function getSlug(): ?string
118
    {
119
        return $this->slug;
120
    }
121
122
    public function resetSlug(): void
123
    {
124
        $this->slug = Random::string(128);
125
    }
126
127
    public function getTitle(): string
128
    {
129
        return $this->title;
130
    }
131
132
    public function setTitle(string $title): void
133
    {
134
        $this->title = $title;
135
    }
136
137
    public function getContent(): string
138
    {
139
        return $this->content;
140
    }
141
142
    public function setContent(string $content): void
143
    {
144
        $this->content = $content;
145
    }
146
147
    public function isPublic(): bool
148
    {
149
        return $this->public;
150
    }
151
152
    public function setPublic(bool $public): void
153
    {
154
        $this->public = $public;
155
    }
156
157
    public function getCreatedAt(): DateTimeImmutable
158
    {
159
        return $this->createdAt;
160
    }
161
162
    public function getUpdatedAt(): DateTimeImmutable
163
    {
164
        return $this->updatedAt;
165
    }
166
167
    public function getDeletedAt(): ?DateTimeImmutable
168
    {
169
        return $this->deletedAt;
170
    }
171
172
    public function setUser(User $user)
173
    {
174
        $this->user = $user;
175
    }
176
177
    public function getUser(): User
178
    {
179
        return $this->user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->user could return the type Cycle\ORM\Promise\Reference which is incompatible with the type-hinted return App\Entity\User. Consider adding an additional type-check to rule them out.
Loading history...
180
    }
181
182
    public function getPublishedAt(): ?DateTimeImmutable
183
    {
184
        return $this->publishedAt;
185
    }
186
187
    public function setPublishedAt(?DateTimeImmutable $publishedAt): void
188
    {
189
        $this->publishedAt = $publishedAt;
190
    }
191
192
    /**
193
     * @return ArrayCollection|Comment[]
194
     */
195
    public function getComments()
196
    {
197
        return $this->comments;
198
    }
199
200
    public function addComment(Comment $post): void
201
    {
202
        $this->comments->add($post);
203
    }
204
205
    /**
206
     * @return ArrayCollection|Tag[]
207
     */
208
    public function getTags()
209
    {
210
        return $this->tags;
211
    }
212
213
    public function addTag(Tag $post): void
214
    {
215
        $this->tags->add($post);
216
    }
217
}
218