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

Comment::getUser()   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;
68
69
    /**
70
     * @BelongsTo(target="App\Blog\Entity\Post", nullable=false)
71
     * @var Post|\Cycle\ORM\Promise\Reference
72
     */
73
    private $post;
74
75
    public function __construct(string $content)
76
    {
77
        $this->content = $content;
78
        $this->created_at = new DateTimeImmutable();
79
        $this->updated_at = new DateTimeImmutable();
80
    }
81
82
    public function getId(): ?int
83
    {
84
        return $this->id;
85
    }
86
87
    public function getContent(): string
88
    {
89
        return $this->content;
90
    }
91
92
    public function setContent(string $content): void
93
    {
94
        $this->content = $content;
95
    }
96
97
    public function isPublic(): bool
98
    {
99
        return $this->public;
100
    }
101
102
    public function setPublic(bool $public): void
103
    {
104
        $this->public = $public;
105
    }
106
107
    public function getCreatedAt(): DateTimeImmutable
108
    {
109
        return $this->created_at;
110
    }
111
112
    public function getUpdatedAt(): DateTimeImmutable
113
    {
114
        return $this->updated_at;
115
    }
116
117
    public function getDeletedAt(): ?DateTimeImmutable
118
    {
119
        return $this->deleted_at;
120
    }
121
122
    public function setUser(User $user)
123
    {
124
        $this->user = $user;
125
    }
126
127
    public function getUser(): User
128
    {
129
        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...
130
    }
131
132
    public function setPost(Post $post)
133
    {
134
        $this->post = $post;
135
    }
136
137
    public function getPost(): Post
138
    {
139
        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. Consider adding an additional type-check to rule them out.
Loading history...
140
    }
141
142
    public function getPublishedAt(): ?DateTimeImmutable
143
    {
144
        return $this->published_at;
145
    }
146
147
    public function setPublishedAt(?DateTimeImmutable $published_at): void
148
    {
149
        $this->published_at = $published_at;
150
    }
151
}
152