Completed
Push — master ( d15cf4...5163a0 )
by Valentyn
06:05
created

Movie   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 203
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 93.02%

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 2
dl 0
loc 203
ccs 40
cts 43
cp 0.9302
rs 10
c 0
b 0
f 0

16 Methods

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