Passed
Branch master (465d67)
by vincent
02:35
created

Movie::getCast()   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
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
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 vfalies\tmdb\Items;
16
17
use vfalies\tmdb\Abstracts\Item;
18
use vfalies\tmdb\Interfaces\Items\MovieInterface;
19
use vfalies\tmdb\Traits\ElementTrait;
20
use vfalies\tmdb\Items\MovieCredit;
21
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
22
use vfalies\tmdb\Results\Image;
23
use vfalies\tmdb\Interfaces\TmdbInterface;
24
use vfalies\tmdb\Results\Movie as ResultMovie;
25
26
/**
27
 * Movie class
28
 * @package Tmdb
29
 * @author Vincent Faliès <[email protected]>
30
 * @copyright Copyright (c) 2017
31
 */
32
class Movie extends Item implements MovieInterface
33
{
34
35
    use ElementTrait;
36
37
    /**
38
     * Constructor
39
     * @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb
40
     * @param int $movie_id
41
     * @param array $options
42
     */
43 39
    public function __construct(TmdbInterface $tmdb, $movie_id, array $options = array())
44
    {
45 39
        parent::__construct($tmdb, $movie_id, $options, 'movie');
46 38
    }
47
48
    /**
49
     * Get movie genres
50
     * @return array
51
     */
52 2
    public function getGenres()
53
    {
54 2
        if (isset($this->data->genres))
55
        {
56 1
            return $this->data->genres;
57
        }
58 1
        return [];
59
    }
60
61
    /**
62
     * Get movie title
63
     * @return string
64
     */
65 2
    public function getTitle()
66
    {
67 2
        if (isset($this->data->title))
68
        {
69 1
            return $this->data->title;
70
        }
71 1
        return '';
72
    }
73
74
    /**
75
     * Get movie overview
76
     * @return string
77
     */
78 2
    public function getOverview()
79
    {
80 2
        if (isset($this->data->overview))
81
        {
82 1
            return $this->data->overview;
83
        }
84 1
        return '';
85
    }
86
87
    /**
88
     * Get movie release date
89
     * @return string
90
     */
91 2
    public function getReleaseDate()
92
    {
93 2
        if (isset($this->data->release_date))
94
        {
95 1
            return $this->data->release_date;
96
        }
97 1
        return '';
98
    }
99
100
    /**
101
     * Get movie original title
102
     * @return string
103
     */
104 2
    public function getOriginalTitle()
105
    {
106 2
        if (isset($this->data->original_title))
107
        {
108 1
            return $this->data->original_title;
109
        }
110 1
        return '';
111
    }
112
113
    /**
114
     * Get movie note
115
     * @return float
116
     */
117 2
    public function getNote()
118
    {
119 2
        if (isset($this->data->vote_average))
120
        {
121 1
            return $this->data->vote_average;
122
        }
123 1
        return 0;
124
    }
125
126
    /**
127
     * Get movie id
128
     * @return int
129
     */
130 1
    public function getId()
131
    {
132 1
        return $this->id;
133
    }
134
135
    /**
136
     * Get IMDB movie id
137
     * @return string
138
     */
139 2
    public function getIMDBId()
140
    {
141 2
        if (isset($this->data->imdb_id))
142
        {
143 1
            return $this->data->imdb_id;
144
        }
145 1
        return '';
146
    }
147
148
    /**
149
     * Get movie tagline
150
     * @return string
151
     */
152 2
    public function getTagLine()
153
    {
154 2
        if (isset($this->data->tagline))
155
        {
156 1
            return $this->data->tagline;
157
        }
158 1
        return '';
159
    }
160
161
    /**
162
     * Get collection id
163
     * @return int
164
     */
165 2
    public function getCollectionId()
166
    {
167 2
        if (!empty($this->data->belongs_to_collection))
168
        {
169 1
            return (int) $this->data->belongs_to_collection->id;
170
        }
171 1
        return 0;
172
    }
173
174
    /**
175
     * Get movie crew
176
     * @return \Generator|Results\Crew
177
     */
178 1
    public function getCrew()
179
    {
180 1
        $credit = new MovieCredit($this->tmdb, $this->id);
181 1
        return $credit->getCrew();
182
    }
183
184
    /**
185
     * Get movie cast
186
     * @return \Generator|Results\Cast
187
     */
188 9
    public function getCast()
189
    {
190 9
        $cast = new MovieCredit($this->tmdb, $this->id);
191 9
        return $cast->getCast();
192
    }
193
194
    /**
195
     * Get production compagnies
196
     * @return \Generator|stdClass
197
     */
198 1
    public function getProductionCompanies()
199
    {
200 1
        if (!empty($this->data->production_companies))
201
        {
202 1
            foreach ($this->data->production_companies as $p)
203
            {
204 1
                $res       = new \stdClass();
205 1
                $res->id   = $p->id;
206 1
                $res->name = $p->name;
207
208 1
                yield $res;
209
            }
210
        }
211 1
    }
212
213
    /**
214
     * Get production countries
215
     * @return \Generator|stdClass
216
     */
217 1
    public function getProductionCountries()
218
    {
219 1
        if (!empty($this->data->production_countries))
220
        {
221 1
            foreach ($this->data->production_countries as $c)
222
            {
223 1
                $res             = new \stdClass();
224 1
                $res->iso_3166_1 = $c->iso_3166_1;
225 1
                $res->name       = $c->name;
226
227 1
                yield $res;
228
            }
229
        }
230 1
    }
231
232
    /**
233
     * Get image backdrops list
234
     * @return \Generator|Results\Image
235
     */
236 1
    public function getBackdrops()
237
    {
238 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/' . (int) $this->id . '/images', null, $this->params);
239
240 1
        foreach ($data->backdrops as $b)
241
        {
242 1
            $image = new Image($this->tmdb, $this->id, $b);
243 1
            yield $image;
244
        }
245 1
    }
246
247
    /**
248
     * Get image posters list
249
     * @return \Generator|Results\Image
250
     */
251 1
    public function getPosters()
252
    {
253 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/' . (int) $this->id . '/images', null, $this->params);
254
255 1
        foreach ($data->posters as $b)
256
        {
257 1
            $image = new Image($this->tmdb, $this->id, $b);
258 1
            yield $image;
259
        }
260 1
    }
261
262
    /**
263
     * Get similar movies from current movie
264
     * @return \Generator|Results\Movie
265
     */
266 1
    public function getSimilar()
267
    {
268 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/' . (int) $this->id . '/similar', null, $this->params);
269
270 1
        foreach ($data->results as $s)
271
        {
272 1
            $movie = new ResultMovie($this->tmdb, $s);
273 1
            yield $movie;
274
        }
275 1
    }
276
}
277