Completed
Push — master ( 0c2413...d80943 )
by one
07:40
created

Movie::setPublicationDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * (c) Lukasz D. Tulikowski <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace App\Entity;
13
14
use App\Traits\IdColumnTrait;
15
use App\Traits\TimeAwareTrait;
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Doctrine\ORM\Mapping as ORM;
19
use JMS\Serializer\Annotation as JMS;
20
use Symfony\Component\Validator\Constraints as Assert;
21
22
/**
23
 * @ORM\Entity(repositoryClass="App\Repository\MovieRepository")
24
 *
25
 * @JMS\ExclusionPolicy("ALL")
26
 */
27
class Movie
28
{
29
    use IdColumnTrait;
30
    use TimeAwareTrait;
31
32
    /**
33
     * @var int
34
     *
35
     * @ORM\Column(type="integer")
36
     *
37
     * @Assert\NotBlank
38
     *
39
     * @JMS\Expose
40
     */
41
    protected $duration;
42
43
    /**
44
     * @var string
45
     *
46
     * @ORM\Column(type="string")
47
     *
48
     * @Assert\NotBlank
49
     *
50
     * @JMS\Expose
51
     */
52
    protected $title;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(type="text")
58
     *
59
     * @Assert\NotBlank
60
     */
61
    protected $description;
62
63
    /**
64
     * @var string
65
     *
66
     * @ORM\Column(type="text")
67
     *
68
     * @Assert\NotBlank
69
     *
70
     * @JMS\Expose
71
     */
72
    protected $director;
73
74
    /**
75
     * @var \DateTimeInterface
76
     *
77
     * @ORM\Column(type="datetime")
78
     *
79
     * @Assert\NotBlank
80
     *
81
     * @JMS\Expose
82
     */
83
    protected $publicationDate;
84
85
    /**
86
     * @var ArrayCollection|Review[]
87
     *
88
     * @ORM\OneToMany(targetEntity="App\Entity\Review", mappedBy="movie")
89
     *
90
     * @JMS\Groups({"reviews"})
91
     */
92
    protected $reviews;
93
94
    /**
95
     * @var ArrayCollection|User[]
96
     *
97
     * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="movies")
98
     *
99
     * @JMS\Groups({"audience"})
100
     */
101
    protected $audience;
102
103
    /**
104
     * Movie constructor.
105
     */
106 2
    public function __construct()
107
    {
108 2
        $this->reviews = new ArrayCollection();
109 2
        $this->audience = new ArrayCollection();
110 2
    }
111
112
    /**
113
     * @return int|null
114
     */
115 3
    public function getDuration(): ?int
116
    {
117 3
        return $this->duration;
118
    }
119
120
    /**
121
     * @param int $duration
122
     *
123
     * @return Movie
124
     */
125 3
    public function setDuration(int $duration): self
126
    {
127 3
        $this->duration = $duration;
128
129 3
        return $this;
130
    }
131
132
    /**
133
     * @return string|null
134
     */
135 3
    public function getTitle(): ?string
136
    {
137 3
        return $this->title;
138
    }
139
140
    /**
141
     * @param string|null $title
142
     *
143
     * @return Movie
144
     */
145 2
    public function setTitle(string $title): self
146
    {
147 2
        $this->title = $title;
148
149 2
        return $this;
150
    }
151
152
    /**
153
     * @return string|null
154
     */
155 3
    public function getDescription(): ?string
156
    {
157 3
        return $this->description;
158
    }
159
160
    /**
161
     * @param string $description
162
     *
163
     * @return Movie
164
     */
165 2
    public function setDescription(string $description): self
166
    {
167 2
        $this->description = $description;
168
169 2
        return $this;
170
    }
171
172
    /**
173
     * @return string|null
174
     */
175 3
    public function getDirector(): ?string
176
    {
177 3
        return $this->director;
178
    }
179
180
    /**
181
     * @param string $director
182
     *
183
     * @return Movie
184
     */
185 2
    public function setDirector(string $director): self
186
    {
187 2
        $this->director = $director;
188
189 2
        return $this;
190
    }
191
192
    /**
193
     * @return \DateTimeInterface|null
194
     */
195 3
    public function getPublicationDate(): ?\DateTimeInterface
196
    {
197 3
        return $this->publicationDate;
198
    }
199
200
    /**
201
     * @param \DateTimeInterface $publicationDate
202
     *
203
     * @return Movie
204
     */
205 2
    public function setPublicationDate(?\DateTimeInterface $publicationDate): self
206
    {
207 2
        $this->publicationDate = $publicationDate;
208
209 2
        return $this;
210
    }
211
212
    /**
213
     * @return Collection|Review[]
214
     */
215
    public function getReviews(): Collection
216
    {
217
        return $this->reviews;
218
    }
219
220
    /**
221
     * @param Review $review
222
     *
223
     * @return Movie
224
     */
225
    public function addReview(Review $review): self
226
    {
227
        if (!$this->reviews->contains($review)) {
228
            $this->reviews[] = $review;
229
            $review->setMovie($this);
230
        }
231
232
        return $this;
233
    }
234
235
    /**
236
     * @param Review $review
237
     *
238
     * @return Movie
239
     */
240
    public function removeReview(Review $review): self
241
    {
242
        if ($this->reviews->contains($review)) {
243
            $this->reviews->removeElement($review);
244
            // set the owning side to null (unless already changed)
245
            if ($review->getMovie() === $this) {
246
                $review->setMovie(null);
247
            }
248
        }
249
250
        return $this;
251
    }
252
253
    /**
254
     * @return Collection|User[]
255
     */
256
    public function getAudience(): Collection
257
    {
258
        return $this->audience;
259
    }
260
261
    /**
262
     * @param User $audience
263
     *
264
     * @return Movie
265
     */
266
    public function addAudience(User $audience): self
267
    {
268
        if (!$this->audience->contains($audience)) {
269
            $this->audience[] = $audience;
270
            $audience->addMovie($this);
271
        }
272
273
        return $this;
274
    }
275
276
    /**
277
     * @param User $audience
278
     *
279
     * @return Movie
280
     */
281
    public function removeAudience(User $audience): self
282
    {
283
        if ($this->audience->contains($audience)) {
284
            $this->audience->removeElement($audience);
285
            $audience->removeMovie($this);
286
        }
287
288
        return $this;
289
    }
290
}
291