Passed
Branch release/1.5.0 (d52397)
by vincent
02:35
created

Movie::getPosters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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