Comment::isPublic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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