CBlog::setBlogSubtitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use DateTime;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use Stringable;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
#[ORM\Table(name: 'c_blog')]
19
#[ORM\Entity]
20
class CBlog extends AbstractResource implements ResourceInterface, Stringable
21
{
22
    #[ORM\Column(name: 'iid', type: 'integer')]
23
    #[ORM\Id]
24
    #[ORM\GeneratedValue]
25
    protected ?int $iid = null;
26
27
    #[Assert\NotBlank]
28
    #[ORM\Column(name: 'title', type: 'text', nullable: false)]
29
    protected string $title;
30
31
    #[ORM\Column(name: 'blog_subtitle', type: 'string', length: 250, nullable: true)]
32
    protected ?string $blogSubtitle = null;
33
34
    #[ORM\Column(name: 'date_creation', type: 'datetime', nullable: false)]
35
    protected DateTime $dateCreation;
36
37
    #[ORM\OneToMany(mappedBy: 'blog', targetEntity: CBlogAttachment::class, cascade: ['persist', 'remove'])]
38
    private Collection $attachments;
39
40
    public function __construct()
41
    {
42
        $this->attachments = new ArrayCollection();
43
    }
44
45
    public function getIid(): ?int
46
    {
47
        return $this->iid;
48
    }
49
50
    public function getTitle(): string
51
    {
52
        return $this->title;
53
    }
54
55
    public function setTitle(string $title): self
56
    {
57
        $this->title = $title;
58
59
        return $this;
60
    }
61
62
    public function getBlogSubtitle(): ?string
63
    {
64
        return $this->blogSubtitle;
65
    }
66
67
    public function setBlogSubtitle(?string $blogSubtitle): self
68
    {
69
        $this->blogSubtitle = $blogSubtitle;
70
71
        return $this;
72
    }
73
74
    public function getDateCreation(): DateTime
75
    {
76
        return $this->dateCreation;
77
    }
78
79
    public function setDateCreation(DateTime $dateCreation): self
80
    {
81
        $this->dateCreation = $dateCreation;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return Collection<int, CBlogAttachment>
88
     */
89
    public function getAttachments(): Collection
90
    {
91
        return $this->attachments;
92
    }
93
94
    public function addAttachment(CBlogAttachment $attachment): self
95
    {
96
        if (!$this->attachments->contains($attachment)) {
97
            $this->attachments->add($attachment);
98
            $attachment->setBlog($this);
99
        }
100
101
        return $this;
102
    }
103
104
    public function removeAttachment(CBlogAttachment $attachment): self
105
    {
106
        if ($this->attachments->removeElement($attachment)) {
107
            if ($attachment->getBlog() === $this) {
108
                $attachment->setBlog(null);
109
            }
110
        }
111
112
        return $this;
113
    }
114
115
    public function getResourceIdentifier(): int
116
    {
117
        return $this->getIid();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getIid() could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
118
    }
119
120
    public function getResourceName(): string
121
    {
122
        return $this->getTitle();
123
    }
124
125
    public function setResourceName(string $name): self
126
    {
127
        return $this->setTitle($name);
128
    }
129
130
    public function __toString(): string
131
    {
132
        return $this->getTitle();
133
    }
134
}
135