Passed
Branch release/1.5.0 (5f009d)
by vincent
05:05
created

TVShow::getNumberSeasons()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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