Comment::setPost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NewsBundle\Model;
15
16
abstract class Comment implements CommentInterface
17
{
18
    /**
19
     * Name of the author.
20
     *
21
     * @var string|null
22
     */
23
    protected $name;
24
25
    /**
26
     * Email of the author.
27
     *
28
     * @var string|null
29
     */
30
    protected $email;
31
32
    /**
33
     * Website url of the author.
34
     *
35
     * @var string|null
36
     */
37
    protected $url;
38
39
    /**
40
     * Comment content.
41
     *
42
     * @var string
43
     */
44
    protected $message;
45
46
    /**
47
     * Comment created date.
48
     *
49
     * @var \DateTime
50
     */
51
    protected $createdAt;
52
53
    /**
54
     * Last update date.
55
     *
56
     * @var \DateTime
57
     */
58
    protected $updatedAt;
59
60
    /**
61
     * Moderation status.
62
     *
63
     * @var int
64
     */
65
    protected $status = self::STATUS_VALID;
66
67
    /**
68
     * Post for which the comment is related to.
69
     *
70
     * @var PostInterface
71
     */
72
    protected $post;
73
74
    public function __toString()
75
    {
76
        return $this->getName() ?: 'n-a';
77
    }
78
79
    public function setName($name): void
80
    {
81
        $this->name = $name;
82
    }
83
84
    public function getName()
85
    {
86
        return $this->name;
87
    }
88
89
    public function setEmail($email): void
90
    {
91
        $this->email = $email;
92
    }
93
94
    public function getEmail()
95
    {
96
        return $this->email;
97
    }
98
99
    public function setUrl($url): void
100
    {
101
        $this->url = $url;
102
    }
103
104
    public function getUrl()
105
    {
106
        return $this->url;
107
    }
108
109
    public function setMessage($message): void
110
    {
111
        $this->message = $message;
112
    }
113
114
    public function getMessage()
115
    {
116
        return $this->message;
117
    }
118
119
    public function setCreatedAt(?\DateTime $createdAt = null): void
120
    {
121
        $this->createdAt = $createdAt;
122
    }
123
124
    public function getCreatedAt()
125
    {
126
        return $this->createdAt;
127
    }
128
129
    public function setUpdatedAt(?\DateTime $updatedAt = null): void
130
    {
131
        $this->updatedAt = $updatedAt;
132
    }
133
134
    public function getUpdatedAt()
135
    {
136
        return $this->updatedAt;
137
    }
138
139
    public static function getStatusList()
140
    {
141
        return [
142
            self::STATUS_MODERATE => 'moderate',
143
            self::STATUS_INVALID => 'invalid',
144
            self::STATUS_VALID => 'valid',
145
        ];
146
    }
147
148
    public function getStatusCode()
149
    {
150
        $status = self::getStatusList();
151
152
        return isset($status[$this->getStatus()]) ? $status[$this->getStatus()] : null;
153
    }
154
155
    public function preUpdate(): void
156
    {
157
        $this->setUpdatedAt(new \DateTime());
158
    }
159
160
    public function setStatus($status): void
161
    {
162
        $this->status = $status;
163
    }
164
165
    public function getStatus()
166
    {
167
        return $this->status;
168
    }
169
170
    public function setPost($post): void
171
    {
172
        $this->post = $post;
173
    }
174
175
    public function getPost()
176
    {
177
        return $this->post;
178
    }
179
}
180