Completed
Pull Request — master (#29)
by vincent
02:44
created

TVShow::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
 * 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\TVShowInterface;
19
use vfalies\tmdb\Traits\ElementTrait;
20
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
21
use vfalies\tmdb\Results\Image;
22
use vfalies\tmdb\Interfaces\TmdbInterface;
23
use vfalies\tmdb\Results\TVShow as ResultTVShow;
24
25
/**
26
 * TVShow class
27
 * @package Tmdb
28
 * @author Vincent Faliès <[email protected]>
29
 * @copyright Copyright (c) 2017
30
 */
31
class TVShow extends Item implements TVShowInterface
32
{
33
34
    use ElementTrait;
35
36
    /**
37
     * Constructor
38
     * @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb
39
     * @param int $tv_id
40
     * @param array $options
41
     */
42 34
    public function __construct(TmdbInterface $tmdb, $tv_id, array $options = array())
43
    {
44 34
        parent::__construct($tmdb, $tv_id, $options, 'tv');
45 33
    }
46
47
    /**
48
     * Get TV show id
49
     * @return int
50
     */
51 1
    public function getId()
52
    {
53 1
        return $this->id;
54
    }
55
56
    /**
57
     * Get TVSHow genres
58
     * @return array
59
     */
60 2
    public function getGenres()
61
    {
62 2
        if (isset($this->data->genres))
63
        {
64 1
            return $this->data->genres;
65
        }
66 1
        return [];
67
    }
68
69
    /**
70
     * Get TVshow note
71
     *  @return float
72
     */
73 2
    public function getNote()
74
    {
75 2
        if (isset($this->data->vote_average))
76
        {
77 1
            return $this->data->vote_average;
78
        }
79 1
        return 0;
80
    }
81
82
    /**
83
     * Get TVshow number of episodes
84
     * @return int
85
     */
86 2
    public function getNumberEpisodes()
87
    {
88 2
        if (isset($this->data->number_of_episodes))
89
        {
90 1
            return $this->data->number_of_episodes;
91
        }
92 1
        return 0;
93
    }
94
95
    /**
96
     * Get TVShow number of seasons
97
     * @return int
98
     */
99 2
    public function getNumberSeasons()
100
    {
101 2
        if (isset($this->data->number_of_seasons))
102
        {
103 1
            return $this->data->number_of_seasons;
104
        }
105 1
        return 0;
106
    }
107
108
    /**
109
     * Get TVShow original title
110
     * @return string
111
     */
112 2
    public function getOriginalTitle()
113
    {
114 2
        if (isset($this->data->original_name))
115
        {
116 1
            return $this->data->original_name;
117
        }
118 1
        return '';
119
    }
120
121
    /**
122
     * Get TVShow overview
123
     * @return string
124
     */
125 2
    public function getOverview()
126
    {
127 2
        if (isset($this->data->overview))
128
        {
129 1
            return $this->data->overview;
130
        }
131 1
        return '';
132
    }
133
134
    /**
135
     * Get TVShow release date
136
     * @return string
137
     */
138 2
    public function getReleaseDate()
139
    {
140 2
        if (isset($this->data->first_air_date))
141
        {
142 1
            return $this->data->first_air_date;
143
        }
144 1
        return '';
145
    }
146
147
    /**
148
     * Get TVShow status
149
     * @return string
150
     */
151 2
    public function getStatus()
152
    {
153 2
        if (isset($this->data->status))
154
        {
155 1
            return $this->data->status;
156
        }
157 1
        return '';
158
    }
159
160
    /**
161
     * Get TVShow title
162
     * @return string
163
     */
164 2
    public function getTitle()
165
    {
166 2
        if (isset($this->data->name))
167
        {
168 1
            return $this->data->name;
169
        }
170 1
        return '';
171
    }
172
173
    /**
174
     * Get TVShow seasons
175
     * @return \Generator|Results\TVSeason
176
     */
177 6
    public function getSeasons()
178
    {
179 6
        if (!empty($this->data->seasons))
180
        {
181 5
            foreach ($this->data->seasons as $season)
182
            {
183 5
                $season = new \vfalies\tmdb\Results\TVSeason($this->tmdb, $season);
184 5
                yield $season;
185
            }
186
        }
187 2
    }
188
189
    /**
190
     * Get TVShow networks
191
     * @return \Generator|\stdClass
192
     */
193 1
    public function getNetworks()
194
    {
195 1
        if (!empty($this->data->networks))
196
        {
197 1
            foreach ($this->data->networks as $network)
198
            {
199 1
                $n       = new \stdClass();
200 1
                $n->id   = $network->id;
201 1
                $n->name = $network->name;
202
203 1
                yield $n;
204
            }
205
        }
206 1
    }
207
208
    /**
209
     * Backdrops list
210
     * @return \Generator|Results\Image
211
     */
212 1
    public function getBackdrops()
213
    {
214 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/' . (int) $this->id . '/images', null, $this->params);
215
216 1
        foreach ($data->backdrops as $b)
217
        {
218 1
            $image = new Image($this->tmdb, $this->id, $b);
219 1
            yield $image;
220
        }
221 1
    }
222
223
    /**
224
     * Posters list
225
     * @return \Generator|Results\Image
226
     */
227 1
    public function getPosters()
228
    {
229 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/' . (int) $this->id . '/images', null, $this->params);
230
231 1
        foreach ($data->posters as $b)
232
        {
233 1
            $image = new Image($this->tmdb, $this->id, $b);
234 1
            yield $image;
235
        }
236 1
    }
237
238
    /**
239
     * Get Similar TVShow
240
     * @return \Generator|Results\TVShow
241
     */
242 1
    public function getSimilar()
243
    {
244 1
        $similar = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/' . (int) $this->id . '/similar', null, $this->params);
245
246 1
        foreach ($similar->results as $t)
247
        {
248 1
            $tvshow = new ResultTVShow($this->tmdb, $t);
249 1
            yield $tvshow;
250
        }
251 1
    }
252
}
253