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\Items\TVItem; |
18
|
|
|
use VfacTmdb\Interfaces\Items\TVEpisodeInterface; |
19
|
|
|
use VfacTmdb\Results; |
20
|
|
|
use VfacTmdb\Traits\TVEpisodeTrait; |
21
|
|
|
use VfacTmdb\Interfaces\TmdbInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* TVEpisode class |
25
|
|
|
* @package Tmdb |
26
|
|
|
* @author Vincent Faliès <[email protected]> |
27
|
|
|
* @copyright Copyright (c) 2017 |
28
|
|
|
*/ |
29
|
|
|
class TVEpisode extends TVItem implements TVEpisodeInterface |
30
|
|
|
{ |
31
|
|
|
use TVEpisodeTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Season number |
35
|
|
|
* @var int |
36
|
|
|
*/ |
37
|
|
|
protected $season_number; |
38
|
|
|
/** |
39
|
|
|
* Episode number |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
protected $episode_number; |
43
|
|
|
/** |
44
|
|
|
* TVShow Id |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
protected $tv_id; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructor |
51
|
|
|
* @param TmdbInterface $tmdb |
52
|
|
|
* @param int $tv_id |
53
|
|
|
* @param int $season_number |
54
|
|
|
* @param int $episode_number |
55
|
|
|
* @param array $options |
56
|
|
|
*/ |
57
|
24 |
|
public function __construct(TmdbInterface $tmdb, int $tv_id, int $season_number, int $episode_number, array $options = array()) |
58
|
|
|
{ |
59
|
24 |
|
parent::__construct($tmdb, $episode_number, $options, 'tv/' . $tv_id . '/season/' . $season_number.'/episode'); |
60
|
|
|
|
61
|
24 |
|
$this->season_number = $season_number; |
62
|
24 |
|
$this->episode_number = $episode_number; |
63
|
24 |
|
$this->tv_id = $tv_id; |
64
|
|
|
|
65
|
24 |
|
$this->setElementTrait($this->data); |
66
|
24 |
|
$this->setTVEpisodeTrait($tmdb, $this->data); |
67
|
24 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get TV show id |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
3 |
|
public function getId(): int |
74
|
|
|
{ |
75
|
3 |
|
if (isset($this->data->id)) { |
76
|
2 |
|
return (int) $this->data->id; |
77
|
|
|
} |
78
|
1 |
|
return 0; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Air date |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
2 |
|
public function getAirDate() : string |
86
|
|
|
{ |
87
|
2 |
|
if (isset($this->data->air_date)) { |
88
|
1 |
|
return $this->data->air_date; |
89
|
|
|
} |
90
|
1 |
|
return ''; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Episode number |
95
|
|
|
* @return int |
96
|
|
|
*/ |
97
|
2 |
|
public function getEpisodeNumber() : int |
98
|
|
|
{ |
99
|
2 |
|
if (isset($this->data->episode_number)) { |
100
|
1 |
|
return $this->data->episode_number; |
101
|
|
|
} |
102
|
1 |
|
return 0; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Guests stars |
107
|
|
|
* @return \Generator|Results\Cast |
108
|
|
|
*/ |
109
|
1 |
View Code Duplication |
public function getGuestStars() : \Generator |
|
|
|
|
110
|
|
|
{ |
111
|
1 |
|
if (isset($this->data->guest_stars)) { |
112
|
1 |
|
foreach ($this->data->guest_stars as $gs) { |
113
|
1 |
|
$gs->gender = null; |
114
|
1 |
|
$gs->cast_id = null; |
115
|
|
|
|
116
|
1 |
|
$star = new Results\Cast($this->tmdb, $gs); |
117
|
1 |
|
yield $star; |
118
|
|
|
} |
119
|
|
|
} |
120
|
1 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Name |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
2 |
|
public function getName() : string |
127
|
|
|
{ |
128
|
2 |
|
if (isset($this->data->name)) { |
129
|
1 |
|
return $this->data->name; |
130
|
|
|
} |
131
|
1 |
|
return ''; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Note |
136
|
|
|
* @return float |
137
|
|
|
*/ |
138
|
2 |
|
public function getNote() : float |
139
|
|
|
{ |
140
|
2 |
|
if (isset($this->data->vote_average)) { |
141
|
1 |
|
return $this->data->vote_average; |
142
|
|
|
} |
143
|
1 |
|
return 0; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Note count |
148
|
|
|
* @return int |
149
|
|
|
*/ |
150
|
2 |
|
public function getNoteCount() : int |
151
|
|
|
{ |
152
|
2 |
|
if (isset($this->data->vote_count)) { |
153
|
1 |
|
return (int) $this->data->vote_count; |
154
|
|
|
} |
155
|
1 |
|
return 0; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Overview |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
2 |
|
public function getOverview() : string |
163
|
|
|
{ |
164
|
2 |
|
if (isset($this->data->overview)) { |
165
|
1 |
|
return $this->data->overview; |
166
|
|
|
} |
167
|
1 |
|
return ''; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Production code |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
2 |
|
public function getProductionCode() : string |
175
|
|
|
{ |
176
|
2 |
|
if (isset($this->data->production_code)) { |
177
|
1 |
|
return $this->data->production_code; |
178
|
|
|
} |
179
|
1 |
|
return ''; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Season number |
184
|
|
|
* @return int |
185
|
|
|
*/ |
186
|
2 |
|
public function getSeasonNumber() : int |
187
|
|
|
{ |
188
|
2 |
|
if (isset($this->data->season_number)) { |
189
|
1 |
|
return (int) $this->data->season_number; |
190
|
|
|
} |
191
|
1 |
|
return 0; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Image still path |
196
|
|
|
* @return string |
197
|
|
|
*/ |
198
|
2 |
|
public function getStillPath() : string |
199
|
|
|
{ |
200
|
2 |
|
if (isset($this->data->still_path)) { |
201
|
1 |
|
return $this->data->still_path; |
202
|
|
|
} |
203
|
1 |
|
return ''; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
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.