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\TVSeasonInterface; |
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
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* TVSeason class |
26
|
|
|
* @package Tmdb |
27
|
|
|
* @author Vincent Faliès <[email protected]> |
28
|
|
|
* @copyright Copyright (c) 2017 |
29
|
|
|
*/ |
30
|
|
|
class TVSeason extends Item implements TVSeasonInterface |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
use ElementTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Season number |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
protected $season_number; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb |
44
|
|
|
* @param int $tv_id |
45
|
|
|
* @param int $season_number |
46
|
|
|
* @param array $options |
47
|
|
|
* @throws Exception |
48
|
|
|
*/ |
49
|
34 |
|
public function __construct(TmdbInterface $tmdb, $tv_id, $season_number, array $options = array()) |
50
|
|
|
{ |
51
|
34 |
|
parent::__construct($tmdb, $season_number, $options, 'tv/' . $tv_id); |
52
|
|
|
|
53
|
34 |
|
$this->season_number = $season_number; |
54
|
34 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Id |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
2 |
|
public function getId() |
61
|
|
|
{ |
62
|
2 |
|
if (!empty($this->data->id)) |
63
|
|
|
{ |
64
|
1 |
|
return (int) $this->data->id; |
65
|
|
|
} |
66
|
1 |
|
return 0; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Air date |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
2 |
|
public function getAirDate() |
74
|
|
|
{ |
75
|
2 |
|
if (!empty($this->data->air_date)) |
76
|
|
|
{ |
77
|
1 |
|
return $this->data->air_date; |
78
|
|
|
} |
79
|
1 |
|
return ''; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Episode count |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
2 |
|
public function getEpisodeCount() |
87
|
|
|
{ |
88
|
2 |
|
if (!empty($this->data->episodes)) |
89
|
|
|
{ |
90
|
1 |
|
return count($this->data->episodes); |
91
|
|
|
} |
92
|
1 |
|
return 0; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Season number |
97
|
|
|
* @return int |
98
|
|
|
*/ |
99
|
2 |
|
public function getSeasonNumber() |
100
|
|
|
{ |
101
|
2 |
|
if (!empty($this->data->season_number)) |
102
|
|
|
{ |
103
|
1 |
|
return (int) $this->data->season_number; |
104
|
|
|
} |
105
|
1 |
|
return 0; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Episodes list |
110
|
|
|
* @return \Generator|Results\TVEpisode |
111
|
|
|
*/ |
112
|
21 |
|
public function getEpisodes() |
113
|
|
|
{ |
114
|
21 |
|
if (!empty($this->data->episodes)) |
115
|
|
|
{ |
116
|
20 |
|
foreach ($this->data->episodes as $episode) |
117
|
|
|
{ |
118
|
20 |
|
$episode = new \vfalies\tmdb\Results\TVEpisode($this->tmdb, $episode); |
119
|
20 |
|
yield $episode; |
120
|
|
|
} |
121
|
|
|
} |
122
|
2 |
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Name |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
2 |
|
public function getName() |
129
|
|
|
{ |
130
|
2 |
|
if (!empty($this->data->name)) |
131
|
|
|
{ |
132
|
1 |
|
return $this->data->name; |
133
|
|
|
} |
134
|
1 |
|
return ''; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Overview |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
2 |
|
public function getOverview() |
142
|
|
|
{ |
143
|
2 |
|
if (!empty($this->data->overview)) |
144
|
|
|
{ |
145
|
1 |
|
return $this->data->overview; |
146
|
|
|
} |
147
|
1 |
|
return ''; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Posters list |
152
|
|
|
* @return \Generator|Results\Image |
153
|
|
|
*/ |
154
|
1 |
View Code Duplication |
public function getPosters() |
|
|
|
|
155
|
|
|
{ |
156
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/' . (int) $this->id . '/seasons/' . $this->season_number . '/images', null, $this->params); |
157
|
|
|
|
158
|
1 |
|
foreach ($data->posters as $b) |
159
|
|
|
{ |
160
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
161
|
1 |
|
yield $image; |
162
|
|
|
} |
163
|
1 |
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
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.