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

Comment::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Entity;
6
7
use App\Entity\User;
8
use Cycle\Annotated\Annotation\Column;
9
use Cycle\Annotated\Annotation\Entity;
10
use Cycle\Annotated\Annotation\Relation\BelongsTo;
11
use Cycle\Annotated\Annotation\Table;
12
use Cycle\Annotated\Annotation\Table\Index;
13
use DateTimeImmutable;
14
15
/**
16
 * @Entity(
17
 *     mapper="App\Blog\Comment\CommentMapper",
18
 *     constrain="App\Blog\Comment\Scope\PublicScope"
19
 * )
20
 * @Table(
21
 *     indexes={
22
 *         @Index(columns={"public","published_at"})
23
 *     }
24
 * )
25
 */
26
class Comment
27
{
28
    /**
29
     * @Column(type="primary")
30
     */
31
    private ?int $id = null;
32
33
    /**
34
     * @Column(type="bool", default="false")
35
     */
36
    private bool $public = false;
37
38
    /**
39
     * @Column(type="text")
40
     */
41
    private string $content;
42
43
    /**
44
     * @Column(type="datetime")
45
     */
46
    private DateTimeImmutable $created_at;
47
48
    /**
49
     * @Column(type="datetime")
50
     */
51
    private DateTimeImmutable $updated_at;
52
53
    /**
54
     * @Column(type="datetime", nullable=true)
55
     */
56
    private ?DateTimeImmutable $published_at = null;
57
58
    /**
59
     * @Column(type="datetime", nullable=true)
60
     */
61
    private ?DateTimeImmutable $deleted_at = null;
62
63
    /**
64
     * @BelongsTo(target="App\Entity\User", nullable=false, load="eager")
65
     * @var User|\Cycle\ORM\Promise\Reference
66
     */
67
    private $user = null;
68
    private ?int $user_id = null;
0 ignored issues
show
introduced by
The private property $user_id is not used, and could be removed.
Loading history...
69
70
    /**
71
     * @BelongsTo(target="App\Blog\Entity\Post", nullable=false)
72
     * @var Post|\Cycle\ORM\Promise\Reference
73
     */
74
    private $post = null;
75
    private ?int $post_id = null;
0 ignored issues
show
introduced by
The private property $post_id is not used, and could be removed.
Loading history...
76
77
    public function __construct(string $content)
78
    {
79
        $this->content = $content;
80
        $this->created_at = new DateTimeImmutable();
81
        $this->updated_at = new DateTimeImmutable();
82
    }
83
84
    public function getId(): ?int
85
    {
86
        return $this->id;
87
    }
88
89
    public function getContent(): string
90
    {
91
        return $this->content;
92
    }
93
94
    public function setContent(string $content): void
95
    {
96
        $this->content = $content;
97
    }
98
99
    public function isPublic(): bool
100
    {
101
        return $this->public;
102
    }
103
104
    public function setPublic(bool $public): void
105
    {
106
        $this->public = $public;
107
    }
108
109
    public function getCreatedAt(): DateTimeImmutable
110
    {
111
        return $this->created_at;
112
    }
113
114
    public function getUpdatedAt(): DateTimeImmutable
115
    {
116
        return $this->updated_at;
117
    }
118
119
    public function getDeletedAt(): ?DateTimeImmutable
120
    {
121
        return $this->deleted_at;
122
    }
123
124
    public function setUser(User $user): void
125
    {
126
        $this->user = $user;
127
    }
128
129
    public function getUser(): ?User
130
    {
131
        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|null. Consider adding an additional type-check to rule them out.
Loading history...
132
    }
133
134
    public function setPost(Post $post): void
135
    {
136
        $this->post = $post;
137
    }
138
139
    public function getPost(): ?Post
140
    {
141
        return $this->post;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->post could return the type Cycle\ORM\Promise\Reference which is incompatible with the type-hinted return App\Blog\Entity\Post|null. Consider adding an additional type-check to rule them out.
Loading history...
142
    }
143
144
    public function getPublishedAt(): ?DateTimeImmutable
145
    {
146
        return $this->published_at;
147
    }
148
149
    public function setPublishedAt(?DateTimeImmutable $published_at): void
150
    {
151
        $this->published_at = $published_at;
152
    }
153
}
154