Passed
Push — fix_coverage_in_scrutinizer ( cd0379...a04ba4 )
by Herberto
13:22
created

Comment::setPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * @ORM\Entity
19
 * @ORM\Table(name="symfony_demo_comment")
20
 *
21
 * Defines the properties of the Comment entity to represent the blog comments.
22
 * See https://symfony.com/doc/current/book/doctrine.html#creating-an-entity-class
23
 *
24
 * Tip: if you have an existing database, you can generate these entity class automatically.
25
 * See https://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
26
 *
27
 * @author Ryan Weaver <[email protected]>
28
 * @author Javier Eguiluz <[email protected]>
29
 */
30
class Comment
31
{
32
    /**
33
     * @var int
34
     *
35
     * @ORM\Id
36
     * @ORM\GeneratedValue
37
     * @ORM\Column(type="integer")
38
     */
39
    private $id;
40
41
    /**
42
     * @var Post
43
     *
44
     * @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
45
     * @ORM\JoinColumn(nullable=false)
46
     */
47
    private $post;
48
49
    /**
50
     * @var string
51
     *
52
     * @ORM\Column(type="text")
53
     * @Assert\NotBlank(message="comment.blank")
54
     * @Assert\Length(
55
     *     min=5,
56
     *     minMessage="comment.too_short",
57
     *     max=10000,
58
     *     maxMessage="comment.too_long"
59
     * )
60
     */
61
    private $content;
62
63
    /**
64
     * @var \DateTime
65
     *
66
     * @ORM\Column(type="datetime")
67
     * @Assert\DateTime
68
     */
69
    private $publishedAt;
70
71
    /**
72
     * @var User
73
     *
74
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
75
     * @ORM\JoinColumn(nullable=false)
76
     */
77
    private $author;
78
79 1
    public function __construct()
80
    {
81 1
        $this->publishedAt = new \DateTime();
82 1
    }
83
84
    /**
85
     * @Assert\IsTrue(message="comment.is_spam")
86
     */
87 1
    public function isLegitComment(): bool
88
    {
89 1
        $containsInvalidCharacters = false !== mb_strpos($this->content, '@');
90
91 1
        return !$containsInvalidCharacters;
92
    }
93
94 2
    public function getId(): int
95
    {
96 2
        return $this->id;
97
    }
98
99 2
    public function getContent(): ?string
100
    {
101 2
        return $this->content;
102
    }
103
104 1
    public function setContent(string $content): void
105
    {
106 1
        $this->content = $content;
107 1
    }
108
109 2
    public function getPublishedAt(): \DateTime
110
    {
111 2
        return $this->publishedAt;
112
    }
113
114
    public function setPublishedAt(\DateTime $publishedAt): void
115
    {
116
        $this->publishedAt = $publishedAt;
117
    }
118
119 2
    public function getAuthor(): User
120
    {
121 2
        return $this->author;
122
    }
123
124 1
    public function setAuthor(User $author): void
125
    {
126 1
        $this->author = $author;
127 1
    }
128
129 1
    public function getPost(): Post
130
    {
131 1
        return $this->post;
132
    }
133
134 1
    public function setPost(Post $post): void
135
    {
136 1
        $this->post = $post;
137 1
    }
138
}
139