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

Comment   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 124
rs 10
c 0
b 0
f 0
wmc 15

15 Methods

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