Completed
Pull Request — 3.1 (#347)
by Łukasz
16:49 queued 11:36
created

News   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 26
lcom 2
cbo 2
dl 0
loc 209
rs 10
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A setCreatedAt() 0 4 1
A getCreatedAt() 0 4 1
A setCreatorEmail() 0 4 1
A getCreatorEmail() 0 4 1
A setTitle() 0 4 1
A getTitle() 0 4 1
A setSubtitle() 0 4 1
A getSubtitle() 0 4 1
A setDate() 0 4 1
A getDate() 0 4 1
A setVisible() 0 4 1
A isVisible() 0 4 1
A getPhotoKey() 0 4 1
A setPhotoKey() 0 4 1
A getPhoto() 0 4 1
A setPhoto() 0 4 1
A addCategory() 0 4 1
A removeCategory() 0 4 1
A getCategories() 0 4 1
A getTags() 0 4 1
A addTag() 0 7 2
A removeTag() 0 5 1
A setTags() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FSi\FixturesBundle\Entity;
6
7
use DateTimeInterface;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\ORM\Mapping as ORM;
11
use FSi\Bundle\DoctrineExtensionsBundle\Validator\Constraints as UploadableAssert;
12
use FSi\DoctrineExtensions\Uploadable\Mapping\Annotation as Uploadable;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
/**
16
 * @ORM\Entity
17
 * @ORM\Table(name="news")
18
 */
19
class News
20
{
21
    /**
22
     * @ORM\Column(type="integer")
23
     * @ORM\Id
24
     * @ORM\GeneratedValue(strategy="AUTO")
25
     */
26
    protected $id;
27
28
    /**
29
     * @ORM\Column(type="string", length=100)
30
     */
31
    protected $title;
32
33
    /**
34
     * @ORM\Column(type="string", length=100, nullable=true)
35
     */
36
    protected $subtitle;
37
38
    /**
39
     * @ORM\Column(type="date", nullable=true)
40
     */
41
    protected $date;
42
43
    /**
44
     * @ORM\Column(type="boolean")
45
     */
46
    protected $visible = false;
47
48
    /**
49
     * @ORM\Column(type="datetime", name="created_at")
50
     */
51
    protected $createdAt;
52
53
    /**
54
     * @ORM\Column(type="text", name="creator_email")
55
     */
56
    protected $creatorEmail;
57
58
    /**
59
     * @ORM\Column(length=255, nullable=true)
60
     * @Uploadable\Uploadable(targetField="photo")
61
     */
62
    protected $photoKey;
63
64
    /**
65
     * @var \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo
66
     * @UploadableAssert\Image()
67
     */
68
    protected $photo;
69
70
    /**
71
     * @var Category[]|Collection
72
     *
73
     * @ORM\ManyToMany(targetEntity="Category")
74
     */
75
    protected $categories;
76
77
    /**
78
     * @var Tag[]|Collection
79
     *
80
     * @Assert\Valid
81
     * @ORM\OneToMany(targetEntity="Tag", mappedBy="news", cascade={"persist"}, orphanRemoval=true)
82
     */
83
    protected $tags;
84
85
    public function __construct()
86
    {
87
        $this->categories = new ArrayCollection();
88
        $this->tags = new ArrayCollection();
89
        $this->comments = new ArrayCollection();
0 ignored issues
show
Bug introduced by
The property comments does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
90
    }
91
92
    public function getId(): ?int
93
    {
94
        return $this->id;
95
    }
96
97
    public function setCreatedAt(DateTimeInterface $createdAt): void
98
    {
99
        $this->createdAt = $createdAt;
100
    }
101
102
    public function getCreatedAt(): ?DateTimeInterface
103
    {
104
        return $this->createdAt;
105
    }
106
107
    public function setCreatorEmail(?string $creatorEmail): void
108
    {
109
        $this->creatorEmail = $creatorEmail;
110
    }
111
112
    public function getCreatorEmail(): ?string
113
    {
114
        return $this->creatorEmail;
115
    }
116
117
    public function setTitle(?string $title): void
118
    {
119
        $this->title = $title;
120
    }
121
122
    public function getTitle(): ?string
123
    {
124
        return $this->title;
125
    }
126
127
    public function setSubtitle(?string $subtitle): void
128
    {
129
        $this->subtitle = $subtitle;
130
    }
131
132
    public function getSubtitle(): ?string
133
    {
134
        return $this->subtitle;
135
    }
136
137
    public function setDate(?DateTimeInterface $date): void
138
    {
139
        $this->date = $date;
140
    }
141
142
    public function getDate(): ?DateTimeInterface
143
    {
144
        return $this->date;
145
    }
146
147
    public function setVisible(bool $visible): void
148
    {
149
        $this->visible = $visible;
150
    }
151
152
    public function isVisible(): bool
153
    {
154
        return $this->visible;
155
    }
156
157
    public function getPhotoKey(): ?string
158
    {
159
        return $this->photoKey;
160
    }
161
162
    public function setPhotoKey(?string $photoKey): void
163
    {
164
        $this->photoKey = $photoKey;
165
    }
166
167
    /**
168
     * @return \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo
169
     */
170
    public function getPhoto()
171
    {
172
        return $this->photo;
173
    }
174
175
    /**
176
     * @param \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo $photo
177
     */
178
    public function setPhoto($photo): void
179
    {
180
        $this->photo = $photo;
181
    }
182
183
    public function addCategory(Category $category): void
184
    {
185
        $this->categories->add($category);
186
    }
187
188
    public function removeCategory(Category $category): void
189
    {
190
        $this->categories->removeElement($category);
191
    }
192
193
    /**
194
     * @return Category[]
195
     */
196
    public function getCategories(): array
197
    {
198
        return $this->categories->toArray();
199
    }
200
201
    /**
202
     * @return Tag[]|Collection
203
     */
204
    public function getTags(): Collection
205
    {
206
        return $this->tags;
207
    }
208
209
    public function addTag(Tag $tag): void
210
    {
211
        if (!$this->tags->contains($tag)) {
212
            $tag->setNews($this);
213
            $this->tags->add($tag);
214
        }
215
    }
216
217
    public function removeTag(Tag $tag): void
218
    {
219
        $tag->setNews(null);
220
        $this->tags->removeElement($tag);
221
    }
222
223
    public function setTags(array $tags): void
224
    {
225
        $this->tags = new ArrayCollection($tags);
226
    }
227
}
228