|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb\Items; |
|
4
|
|
|
|
|
5
|
|
|
use vfalies\tmdb\Abstracts\Item; |
|
6
|
|
|
use vfalies\tmdb\Interfaces\Items\TVEpisodeInterface; |
|
7
|
|
|
use vfalies\tmdb\Tmdb; |
|
8
|
|
|
use vfalies\tmdb\Exceptions\NotYetImplementedException; |
|
9
|
|
|
use vfalies\tmdb\Traits\ElementTrait; |
|
10
|
|
|
use vfalies\tmdb\lib\Guzzle\Client as HttpClient; |
|
11
|
|
|
use vfalies\tmdb\Results\Crew; |
|
12
|
|
|
use vfalies\tmdb\Results\Image; |
|
13
|
|
|
|
|
14
|
|
|
class TVEpisode extends Item implements TVEpisodeInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
use ElementTrait; |
|
18
|
|
|
|
|
19
|
|
|
protected $season_number; |
|
20
|
|
|
protected $episode_number; |
|
21
|
|
|
|
|
22
|
22 |
|
public function __construct(Tmdb $tmdb, $tv_id, $season_number, $episode_number, array $options = array()) |
|
23
|
|
|
{ |
|
24
|
22 |
|
parent::__construct($tmdb, $episode_number, $options, 'tv/'.$tv_id.'/'.$season_number); |
|
25
|
|
|
|
|
26
|
22 |
|
$this->season_number = $season_number; |
|
27
|
22 |
|
$this->episode_number = $episode_number; |
|
28
|
22 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get TV show id |
|
32
|
|
|
* @return int |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function getId() |
|
35
|
|
|
{ |
|
36
|
2 |
|
if (isset($this->data->id)) |
|
37
|
|
|
{ |
|
38
|
1 |
|
return (int) $this->data->id; |
|
39
|
|
|
} |
|
40
|
1 |
|
return 0; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
public function getAirDate() |
|
44
|
|
|
{ |
|
45
|
2 |
|
if (isset($this->data->air_date)) |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->data->air_date; |
|
48
|
|
|
} |
|
49
|
1 |
|
return ''; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
View Code Duplication |
public function getCrew() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
1 |
|
if ( ! empty($this->data->crew)) |
|
55
|
|
|
{ |
|
56
|
1 |
|
foreach ($this->data->crew as $crew) |
|
57
|
|
|
{ |
|
58
|
1 |
|
$crew->gender = null; |
|
59
|
|
|
|
|
60
|
1 |
|
$return = new Crew($this->tmdb, $crew); |
|
61
|
1 |
|
yield $return; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
1 |
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
public function getEpisodeNumber() |
|
67
|
|
|
{ |
|
68
|
2 |
|
if (isset($this->data->episode_number)) |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->data->episode_number; |
|
71
|
|
|
} |
|
72
|
1 |
|
return 0; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @codeCoverageIgnore |
|
77
|
|
|
* @throws NotYetImplementedException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getGuestStars() |
|
80
|
|
|
{ |
|
81
|
|
|
throw new NotYetImplementedException; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function getName() |
|
85
|
|
|
{ |
|
86
|
2 |
|
if (isset($this->data->name)) |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->data->name; |
|
89
|
|
|
} |
|
90
|
1 |
|
return ''; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
2 |
|
public function getNote() |
|
94
|
|
|
{ |
|
95
|
2 |
|
if (isset($this->data->vote_average)) |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->data->vote_average; |
|
98
|
|
|
} |
|
99
|
1 |
|
return 0; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
2 |
|
public function getNoteCount() |
|
103
|
|
|
{ |
|
104
|
2 |
|
if (isset($this->data->vote_count)) |
|
105
|
|
|
{ |
|
106
|
1 |
|
return (int) $this->data->vote_count; |
|
107
|
|
|
} |
|
108
|
1 |
|
return 0; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
2 |
|
public function getOverview() |
|
112
|
|
|
{ |
|
113
|
2 |
|
if (isset($this->data->overview)) |
|
114
|
|
|
{ |
|
115
|
1 |
|
return $this->data->overview; |
|
116
|
|
|
} |
|
117
|
1 |
|
return ''; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
2 |
|
public function getProductionCode() |
|
121
|
|
|
{ |
|
122
|
2 |
|
if (isset($this->data->production_code)) |
|
123
|
|
|
{ |
|
124
|
1 |
|
return $this->data->production_code; |
|
125
|
|
|
} |
|
126
|
1 |
|
return ''; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
2 |
|
public function getSeasonNumber() |
|
130
|
|
|
{ |
|
131
|
2 |
|
if (isset($this->data->season_number)) |
|
132
|
|
|
{ |
|
133
|
1 |
|
return (int) $this->data->season_number; |
|
134
|
|
|
} |
|
135
|
1 |
|
return 0; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
2 |
|
public function getStillPath() |
|
139
|
|
|
{ |
|
140
|
2 |
|
if (isset($this->data->still_path)) |
|
141
|
|
|
{ |
|
142
|
1 |
|
return $this->data->still_path; |
|
143
|
|
|
} |
|
144
|
1 |
|
return ''; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
1 |
View Code Duplication |
public function getPosters() |
|
|
|
|
|
|
148
|
|
|
{ |
|
149
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/seasons/'.$this->season_number.'/episode/'.$this->episode_number.'/images', null, $this->params); |
|
150
|
|
|
|
|
151
|
1 |
|
foreach ($data->posters as $b) |
|
152
|
|
|
{ |
|
153
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
154
|
1 |
|
yield $image; |
|
155
|
|
|
} |
|
156
|
1 |
|
} |
|
157
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
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.