Completed
Push — master ( 1302da...3a2ccf )
by Valentyn
03:07
created

Movie::setRuntime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Movies\Entity;
5
6
use App\Genres\Entity\Genre;
7
use App\Movies\DTO\MovieDTO;
8
use App\Translation\TranslatableTrait;
9
use App\Translation\TranslatableInterface;
10
use App\Users\Entity\UserWatchedMovie;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\ORM\Mapping as ORM;
13
use Doctrine\ORM\PersistentCollection;
14
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
15
use Symfony\Component\Validator\Constraints as Assert;
16
use Symfony\Component\Serializer\Annotation\Groups;
17
18
//todo production_countries, production_companies, actors
19
20
/**
21
 * @ORM\Entity(repositoryClass="App\Movies\Repository\MovieRepository")
22
 * @ORM\Table(name="movies")
23
 * @method MovieTranslations getTranslation(string $locale, bool $useFallbackLocale = true)
24
 * @UniqueEntity("tmdb.id")
25
 */
26
class Movie implements TranslatableInterface
27
{
28
    use TranslatableTrait;
29
30
    /**
31
     * @ORM\Id()
32
     * @ORM\GeneratedValue()
33
     * @ORM\Column(type="integer")
34
     * @Groups({"list", "view"})
35
     */
36
    private $id;
37
38
    /**
39
     * @var $translations MovieTranslations[]|ArrayCollection
40
     * @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieTranslations", mappedBy="movie", cascade={"persist", "remove"})
41
     * @Assert\Valid(traverse=true)
42
     * @Groups({"list", "view"})
43
     */
44
    private $translations;
45
46
    /**
47
     * @var $genres Genre[]|ArrayCollection
48
     * @ORM\ManyToMany(targetEntity="App\Genres\Entity\Genre")
49
     * @ORM\JoinTable(name="movies_genres",
50
     *      joinColumns={@ORM\JoinColumn(name="movie_id", referencedColumnName="id")},
51
     *      inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")}
52
     *      )
53
     * @ORM\JoinColumn(nullable=false)
54
     * @Assert\Valid(traverse=true)
55
     * @Groups({"list", "view"})
56
     */
57
    private $genres;
58
59
    /**
60
     * @Groups({"list", "view"})
61
     * @ORM\Column(type="string", length=100)
62
     */
63
    private $originalTitle;
64
65
    /**
66
     * @Groups({"list", "view"})
67
     * @ORM\Column(type="string", length=255, nullable=true)
68
     */
69
    private $originalPosterUrl;
70
71
    /**
72
     * @ORM\Embedded(class="App\Movies\Entity\MovieTMDB", columnPrefix="tmdb_")
73
     * @Assert\Valid(traverse=true)
74
     * @Groups({"list", "view"})
75
     */
76
    private $tmdb;
77
78
    /**
79
     * @ORM\Column(type="string", length=20, nullable=true)
80
     * @Groups({"view"})
81
     */
82
    private $imdbId;
83
84
    /**
85
     * @Groups({"view"})
86
     * @ORM\Column(type="integer", nullable=true, options={"default": 0})
87
     */
88
    private $runtime;
89
90
    /**
91
     * @Groups({"view"})
92
     * @ORM\Column(type="integer", nullable=true, options={"default": 0})
93
     */
94
    private $budget;
95
96
    /**
97
     * @Groups({"list", "view"})
98
     * @ORM\Column(type="date", nullable=true)
99
     */
100
    private $releaseDate;
101
102
103
    /**
104
     * @var $userWatchedList UserWatchedMovie
105
     * @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie", mappedBy="movie")
106
     * @Groups({"ROLE_USER"})
107
     */
108
    private $userWatchedMovie;
109
110
    /**
111
     * @Groups({"ROLE_USER"})
112
     */
113
    private $isWatched;
114
115 3
    public function __construct(MovieDTO $movieDTO, MovieTMDB $tmdb)
116
    {
117 3
        $this->translations = new ArrayCollection();
118 3
        $this->genres = new ArrayCollection();
119
120 3
        $this->originalTitle = $movieDTO->getOriginalTitle();
121 3
        $this->originalPosterUrl = $movieDTO->getOriginalPosterUrl();
122 3
        $this->setImdbId($movieDTO->getImdbId());
123 3
        $this->setBudget($movieDTO->getBudget());
124 3
        $this->setRuntime($movieDTO->getRuntime());
125 3
        $this->setReleaseDate($movieDTO->getReleaseDate());
126 3
        $this->tmdb = $tmdb;
127 3
    }
128
129 9
    public function getId(): ?int
130
    {
131 9
        return $this->id;
132
    }
133
134 3
    public function addGenre(Genre $genre)
135
    {
136 3
        $this->genres->add($genre);
137 3
        return $this;
138
    }
139
140
    public function removeAllGenres()
141
    {
142
        $this->genres->clear();
143
        return $this;
144
    }
145
146
    /**
147
     * @return Genre[]|array
148
     */
149 6
    public function getGenres()
150
    {
151 6
        return $this->genres->toArray();
152
    }
153
154
    public function updateTmdb(MovieTMDB $tmdb)
155
    {
156
        $this->tmdb = $tmdb;
157
    }
158
159
    /**
160
     * @param string $imdbId
161
     * @return Movie
162
     */
163 3
    private function setImdbId(?string $imdbId)
164
    {
165 3
        $this->imdbId = $imdbId;
166 3
        return $this;
167
    }
168
169
    /**
170
     * @param int $runtime
171
     * @return Movie
172
     */
173 3
    private function setRuntime(int $runtime)
174
    {
175 3
        $this->runtime = $runtime;
176 3
        return $this;
177
    }
178
179
    /**
180
     * @param int $budget
181
     * @return Movie
182
     */
183 3
    private function setBudget(int $budget)
184
    {
185 3
        $this->budget = $budget;
186 3
        return $this;
187
    }
188
189
    /**
190
     * @param \DateTimeInterface $releaseDate
191
     * @return Movie
192
     */
193 3
    private function setReleaseDate(\DateTimeInterface $releaseDate)
194
    {
195 3
        $this->releaseDate = $releaseDate;
196 3
        return $this;
197
    }
198
199
    /**
200
     * @return mixed
201
     */
202 6
    public function getOriginalTitle()
203
    {
204 6
        return $this->originalTitle;
205
    }
206
207
    /**
208
     * @return mixed
209
     */
210 6
    public function getOriginalPosterUrl()
211
    {
212 6
        return $this->originalPosterUrl;
213
    }
214
215
    /**
216
     * @return MovieTMDB
217
     */
218 7
    public function getTmdb()
219
    {
220 7
        return $this->tmdb;
221
    }
222
223
    /**
224
     * @return mixed
225
     */
226 1
    public function getImdbId()
227
    {
228 1
        return $this->imdbId;
229
    }
230
231
    /**
232
     * @return mixed
233
     */
234 1
    public function getRuntime()
235
    {
236 1
        return $this->runtime;
237
    }
238
239
    /**
240
     * @return mixed
241
     */
242 1
    public function getBudget()
243
    {
244 1
        return $this->budget;
245
    }
246
247
    /**
248
     * @return mixed
249
     */
250 6
    public function getReleaseDate()
251
    {
252 6
        return $this->releaseDate;
253
    }
254
255 1
    public function getUserWatchedMovie()
256
    {
257 1
        return $this->userWatchedMovie;
258
    }
259
260 1
    public function isWatched()
261
    {
262 1
        $this->isWatched = $this->userWatchedMovie ? true : false;
263 1
        return $this->isWatched;
264
    }
265
}