Post::setCreatedOn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Entity;
4
5
use DateTime;
6
use Decoda\Decoda;
7
use Decoda\Hook\EmoticonHook;
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * @ORM\Entity
12
 * @ORM\Table(name="forum_posts")
13
 */
14
class Post
15
{
16
    /**
17
     * @var int
18
     * @ORM\Id
19
     * @ORM\GeneratedValue
20
     * @ORM\Column(type="integer")
21
     */
22
    protected $id;
23
24
    /**
25
     * @var Thread
26
     * @ORM\ManyToOne(targetEntity="Thread", inversedBy="posts")
27
     * @ORM\JoinColumn(name="thread_id", referencedColumnName="id", nullable=false)
28
     */
29
    protected $thread;
30
31
    /**
32
     * @var int
33
     * @ORM\Column(type="integer")
34
     */
35
    protected $post_number;
36
37
    /**
38
     * @var User
39
     * @ORM\ManyToOne(targetEntity="\App\Entity\User")
40
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
41
     */
42
    protected $user;
43
44
    /**
45
     * @var string
46
     * @ORM\Column(type="string")
47
     */
48
    protected $subject;
49
50
    /**
51
     * @var string
52
     * @ORM\Column(type="text")
53
     */
54
    protected $message;
55
56
    /**
57
     * @var DateTime
58
     * @ORM\Column(type="datetime")
59
     */
60
    protected $created_on;
61
62
    /**
63
     * @return int The ID
64
     */
65
    public function getId(): int
66
    {
67
        return $this->id;
68
    }
69
70
    /**
71
     * @return Thread The thread
72
     */
73
    public function getThread(): Thread
74
    {
75
        return $this->thread;
76
    }
77
78
    /**
79
     * @param Thread $thread The thread
80
     *
81
     * @return $this
82
     */
83
    public function setThread(Thread $thread): self
84
    {
85
        $this->thread = $thread;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @return int The number of posts
92
     */
93
    public function getPostNumber(): int
94
    {
95
        return $this->post_number;
96
    }
97
98
    /**
99
     * @param int $post_number The number of posts
100
     *
101
     * @return $this
102
     */
103
    public function setPostNumber(int $post_number): self
104
    {
105
        $this->post_number = $post_number;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return User The user
112
     */
113
    public function getUser(): User
114
    {
115
        return $this->user;
116
    }
117
118
    /**
119
     * @param User $user The user
120
     *
121
     * @return $this
122
     */
123
    public function setUser(User $user): self
124
    {
125
        $this->user = $user;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return string The subject
132
     */
133
    public function getSubject(): string
134
    {
135
        return $this->subject;
136
    }
137
138
    /**
139
     * @param string $subject The subject
140
     *
141
     * @return $this
142
     */
143
    public function setSubject(string $subject): self
144
    {
145
        $this->subject = $subject;
146
147
        return $this;
148
    }
149
150
    /**
151
     * @return string The message
152
     */
153
    public function getMessage(): string
154
    {
155
        return $this->message;
156
    }
157
158
    /**
159
     * @return string The formatted message
160
     */
161
    public function getFormattedMessage(): string
162
    {
163
        $bbParser = new Decoda($this->message);
164
        $bbParser->defaults();
165
        $bbParser->addHook(new EmoticonHook());
166
167
        return $bbParser->convertLineBreaks($bbParser->parse());
168
    }
169
170
    /**
171
     * @param string $message The message
172
     *
173
     * @return $this
174
     */
175
    public function setMessage(string $message): self
176
    {
177
        $this->message = $message;
178
179
        return $this;
180
    }
181
182
    /**
183
     * @return DateTime The date when the post was created
184
     */
185
    public function getCreatedOn(): DateTime
186
    {
187
        return $this->created_on;
188
    }
189
190
    /**
191
     * @param DateTime $created_on The date when the post was created
192
     *
193
     * @return $this
194
     */
195
    public function setCreatedOn(DateTime $created_on): self
196
    {
197
        $this->created_on = $created_on;
198
199
        return $this;
200
    }
201
202
    /**
203
     * @return array An array of all the properties of an object
204
     */
205
    public function toArray(): array
206
    {
207
        return [
208
            'id' => $this->id,
209
            'thread' => $this->thread,
210
            'post_number' => $this->post_number,
211
            'user' => $this->user,
212
            'subject' => $this->subject,
213
            'message' => $this->message,
214
            'created_on' => $this->created_on,
215
        ];
216
    }
217
}
218