Passed
Push — master ( 9635db...d1c97e )
by vincent
02:31 queued 11s
created

Movie::getVideos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types = 1);
2
/**
3
 * This file is part of the Tmdb package.
4
 *
5
 * (c) Vincent Faliès <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Vincent Faliès <[email protected]>
11
 * @copyright Copyright (c) 2017
12
 */
13
14
15
namespace VfacTmdb\Items;
16
17
use VfacTmdb\Abstracts\Item;
18
use VfacTmdb\Interfaces\Items\MovieInterface;
19
use VfacTmdb\Traits\ElementTrait;
20
use VfacTmdb\Items\MovieCredit;
21
use VfacTmdb\Interfaces\TmdbInterface;
22
use VfacTmdb\Results;
23
24
/**
25
 * Movie class
26
 * @package Tmdb
27
 * @author Vincent Faliès <[email protected]>
28
 * @copyright Copyright (c) 2017
29
 */
30
class Movie extends Item implements MovieInterface
31
{
32
    use ElementTrait;
33
34
    /**
35
     * Constructor
36
     * @param TmdbInterface $tmdb
37
     * @param int $movie_id
38
     * @param array $options
39
     */
40 120
    public function __construct(TmdbInterface $tmdb, int $movie_id, array $options = array())
41
    {
42 120
        parent::__construct($tmdb, $movie_id, $options, 'movie');
43
44 117
        $this->setElementTrait($this->data);
45 117
    }
46
47
    /**
48
     * Get movie genres
49
     * @return array
50
     */
51 6
    public function getGenres() : array
52
    {
53 6
        if (isset($this->data->genres)) {
54 3
            return $this->data->genres;
55
        }
56 3
        return [];
57
    }
58
59
    /**
60
     * Get movie title
61
     * @return string
62
     */
63 6
    public function getTitle() : string
64
    {
65 6
        if (isset($this->data->title)) {
66 3
            return $this->data->title;
67
        }
68 3
        return '';
69
    }
70
71
    /**
72
     * Get movie overview
73
     * @return string
74
     */
75 6
    public function getOverview() : string
76
    {
77 6
        if (isset($this->data->overview)) {
78 3
            return $this->data->overview;
79
        }
80 3
        return '';
81
    }
82
83
    /**
84
     * Get movie release date
85
     * @return string
86
     */
87 6
    public function getReleaseDate() : string
88
    {
89 6
        if (isset($this->data->release_date)) {
90 3
            return $this->data->release_date;
91
        }
92 3
        return '';
93
    }
94
95
    /**
96
     * Get movie original title
97
     * @return string
98
     */
99 6
    public function getOriginalTitle() : string
100
    {
101 6
        if (isset($this->data->original_title)) {
102 3
            return $this->data->original_title;
103
        }
104 3
        return '';
105
    }
106
107
    /**
108
     * Get movie note
109
     * @return float
110
     */
111 6
    public function getNote() : float
112
    {
113 6
        if (isset($this->data->vote_average)) {
114 3
            return $this->data->vote_average;
115
        }
116 3
        return 0;
117
    }
118
119
    /**
120
     * Get movie id
121
     * @return int
122
     */
123 3
    public function getId() : int
124
    {
125 3
        return $this->id;
126
    }
127
128
    /**
129
     * Get IMDB movie id
130
     * @return string
131
     */
132 6
    public function getIMDBId() : string
133
    {
134 6
        if (isset($this->data->imdb_id)) {
135 3
            return $this->data->imdb_id;
136
        }
137 3
        return '';
138
    }
139
140
    /**
141
     * Get movie tagline
142
     * @return string
143
     */
144 6
    public function getTagLine() : string
145
    {
146 6
        if (isset($this->data->tagline)) {
147 3
            return $this->data->tagline;
148
        }
149 3
        return '';
150
    }
151
152
    /**
153
     * Get collection id
154
     * @return int
155
     */
156 6
    public function getCollectionId() : int
157
    {
158 6
        if (!empty($this->data->belongs_to_collection)) {
159 3
            return (int) $this->data->belongs_to_collection->id;
160
        }
161 3
        return 0;
162
    }
163
164
    /**
165
     * Get movie crew
166
     * @return \Generator|Results\Crew
167
     */
168 3
    public function getCrew() : \Generator
169
    {
170 3
        $credit = new MovieCredit($this->tmdb, $this->id);
171 3
        return $credit->getCrew();
172
    }
173
174
    /**
175
     * Get movie cast
176
     * @return \Generator|Results\Cast
177
     */
178 27
    public function getCast() : \Generator
179
    {
180 27
        $cast = new MovieCredit($this->tmdb, $this->id);
181 27
        return $cast->getCast();
182
    }
183
184
    /**
185
     * Get movie videos
186
     *
187
     * @return \Generator|Results\Videos
188
     */
189 3
    public function getVideos() :\Generator
190
    {
191 3
        $videos = new MovieVideos($this->tmdb, $this->id);
192 3
        return $videos->getVideos();
193
    }
194
195
    /**
196
     * Get production compagnies
197
     * @return \Generator|Results\Company
198
     */
199 3
    public function getProductionCompanies() : \Generator
200
    {
201 3
        if (!empty($this->data->production_companies)) {
202 3
            foreach ($this->data->production_companies as $p) {
203 3
                $res            = new \stdClass();
204 3
                $res->id        = $p->id;
205 3
                $res->name      = $p->name;
206 3
                $res->logo_path = null;
207
208 3
                $company        = new Results\Company($this->tmdb, $res);
209 3
                yield $company;
210
            }
211
        }
212 3
    }
213
214
    /**
215
     * Get production countries
216
     * @return \Generator|\stdClass
217
     */
218 3
    public function getProductionCountries() : \Generator
219
    {
220 3
        if (!empty($this->data->production_countries)) {
221 3
            foreach ($this->data->production_countries as $c) {
222 3
                $res             = new \stdClass();
223 3
                $res->iso_3166_1 = $c->iso_3166_1;
224 3
                $res->name       = $c->name;
225
226 3
                yield $res;
227
            }
228
        }
229 3
    }
230
231
    /**
232
     * Get image backdrops list
233
     * @return \Generator|Results\Image
234
     */
235 3 View Code Duplication
    public function getBackdrops() : \Generator
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
236
    {
237 3
        $params = [];
238 3
        $this->tmdb->checkOptionLanguage($this->params, $params);
239 3
        $data = $this->tmdb->getRequest('movie/' . (int) $this->id . '/images', $params);
240
241 3
        foreach ($data->backdrops as $b) {
242 3
            $image = new Results\Image($this->tmdb, $this->id, $b);
243 3
            yield $image;
244
        }
245 3
    }
246
247
    /**
248
     * Get image posters list
249
     * @return \Generator|Results\Image
250
     */
251 3 View Code Duplication
    public function getPosters() : \Generator
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
    {
253 3
        $params = [];
254 3
        $this->tmdb->checkOptionLanguage($this->params, $params);
255 3
        $data = $this->tmdb->getRequest('movie/' . (int) $this->id . '/images', $params);
256
257 3
        foreach ($data->posters as $b) {
258 3
            $image = new Results\Image($this->tmdb, $this->id, $b);
259 3
            yield $image;
260
        }
261 3
    }
262
263
    /**
264
     * Get similar movies from current movie
265
     * @return \Generator|Results\Movie
266
     */
267 3 View Code Duplication
    public function getSimilar() : \Generator
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
    {
269 3
        $params = [];
270 3
        $this->tmdb->checkOptionLanguage($this->params, $params);
271 3
        $this->tmdb->checkOptionPage($this->params, $params);
272 3
        $data = $this->tmdb->getRequest('movie/' . (int) $this->id . '/similar', $params);
273
274 3
        foreach ($data->results as $s) {
275 3
            $movie = new Results\Movie($this->tmdb, $s);
276 3
            yield $movie;
277
        }
278 3
    }
279
}
280