Completed
Push — master ( d47add...fca143 )
by Valentyn
02:52
created

Movie   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 251
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 22
lcom 3
cbo 3
dl 0
loc 251
ccs 51
cts 57
cp 0.8947
rs 10
c 0
b 0
f 0

20 Methods

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