Completed
Push — master ( 1a9043...984777 )
by Valentyn
08:31
created

Movie::getGenres()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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