vfalies /
tmdb
| 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-2021 |
||
| 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-2021 |
||
| 28 | */ |
||
| 29 | class TVEpisode extends TVItem implements TVEpisodeInterface |
||
| 30 | { |
||
| 31 | use TVEpisodeTrait; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | |||
| 33 | /** |
||
| 34 | * Constructor |
||
| 35 | * @param TmdbInterface $tmdb |
||
| 36 | * @param int $tv_id |
||
| 37 | * @param int $season_number |
||
| 38 | * @param int $episode_number |
||
| 39 | * @param array $options |
||
| 40 | */ |
||
| 41 | 75 | public function __construct(TmdbInterface $tmdb, int $tv_id, int $season_number, int $episode_number, array $options = array()) |
|
| 42 | { |
||
| 43 | 75 | parent::__construct($tmdb, $episode_number, $options, 'tv/' . $tv_id . '/season/' . $season_number . '/episode'); |
|
| 44 | |||
| 45 | 75 | $this->season_number = $season_number; |
|
| 46 | 75 | $this->episode_number = $episode_number; |
|
| 47 | 75 | $this->tv_id = $tv_id; |
|
| 48 | |||
| 49 | 75 | $this->setElementTrait($this->data); |
|
| 50 | 75 | $this->setTVEpisodeTrait($tmdb, $this->data); |
|
| 51 | 75 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Get TV show id |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | 12 | public function getId(): int |
|
| 58 | { |
||
| 59 | 12 | if (isset($this->data->id)) { |
|
| 60 | 9 | return (int) $this->data->id; |
|
| 61 | } |
||
| 62 | 3 | return 0; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Air date |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 6 | public function getAirDate() : string |
|
| 70 | { |
||
| 71 | 6 | if (isset($this->data->air_date)) { |
|
| 72 | 3 | return $this->data->air_date; |
|
| 73 | } |
||
| 74 | 3 | return ''; |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Episode number |
||
| 79 | * @return int |
||
| 80 | */ |
||
| 81 | 6 | public function getEpisodeNumber() : int |
|
| 82 | { |
||
| 83 | 6 | if (isset($this->data->episode_number)) { |
|
| 84 | 3 | return $this->data->episode_number; |
|
| 85 | } |
||
| 86 | 3 | return 0; |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Guests stars |
||
| 91 | * @return \Generator|Results\Cast |
||
| 92 | */ |
||
| 93 | 3 | public function getGuestStars() : \Generator |
|
| 94 | { |
||
| 95 | 3 | if (isset($this->data->guest_stars)) { |
|
| 96 | 3 | foreach ($this->data->guest_stars as $gs) { |
|
| 97 | 3 | $gs->gender = null; |
|
| 98 | 3 | $gs->cast_id = null; |
|
| 99 | |||
| 100 | 3 | $star = new Results\Cast($this->tmdb, $gs); |
|
| 101 | 3 | yield $star; |
|
| 102 | } |
||
| 103 | } |
||
| 104 | 3 | } |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Name |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | 6 | public function getName() : string |
|
| 111 | { |
||
| 112 | 6 | if (isset($this->data->name)) { |
|
| 113 | 3 | return $this->data->name; |
|
| 114 | } |
||
| 115 | 3 | return ''; |
|
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Note |
||
| 120 | * @return float |
||
| 121 | */ |
||
| 122 | 6 | public function getNote() : float |
|
| 123 | { |
||
| 124 | 6 | if (isset($this->data->vote_average)) { |
|
| 125 | 3 | return $this->data->vote_average; |
|
| 126 | } |
||
| 127 | 3 | return 0; |
|
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Note count |
||
| 132 | * @return int |
||
| 133 | */ |
||
| 134 | 6 | public function getNoteCount() : int |
|
| 135 | { |
||
| 136 | 6 | if (isset($this->data->vote_count)) { |
|
| 137 | 3 | return (int) $this->data->vote_count; |
|
| 138 | } |
||
| 139 | 3 | return 0; |
|
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Overview |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | 6 | public function getOverview() : string |
|
| 147 | { |
||
| 148 | 6 | if (isset($this->data->overview)) { |
|
| 149 | 3 | return $this->data->overview; |
|
| 150 | } |
||
| 151 | 3 | return ''; |
|
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Production code |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | 6 | public function getProductionCode() : string |
|
| 159 | { |
||
| 160 | 6 | if (isset($this->data->production_code)) { |
|
| 161 | 3 | return $this->data->production_code; |
|
| 162 | } |
||
| 163 | 3 | return ''; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Season number |
||
| 168 | * @return int |
||
| 169 | */ |
||
| 170 | 6 | public function getSeasonNumber() : int |
|
| 171 | { |
||
| 172 | 6 | if (isset($this->data->season_number)) { |
|
| 173 | 3 | return (int) $this->data->season_number; |
|
| 174 | } |
||
| 175 | 3 | return 0; |
|
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Image still path |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | 6 | public function getStillPath() : string |
|
| 183 | { |
||
| 184 | 6 | if (isset($this->data->still_path)) { |
|
| 185 | 3 | return $this->data->still_path; |
|
| 186 | } |
||
| 187 | 3 | return ''; |
|
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get the underlying ItemChanges object for this Item |
||
| 192 | * @param array $options Array of options for the request |
||
| 193 | * @return TVEpisodeItemChanges |
||
| 194 | */ |
||
| 195 | 3 | public function getItemChanges(array $options = array()) : TVEpisodeItemChanges |
|
| 196 | { |
||
| 197 | 3 | return new TVEpisodeItemChanges($this->tmdb, $this->getId(), $options); |
|
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get this Item's Changes |
||
| 202 | * @param array $options Array of options for the request |
||
| 203 | * @return \Generator |
||
| 204 | */ |
||
| 205 | 3 | public function getChanges(array $options = array()) : \Generator |
|
| 206 | { |
||
| 207 | 3 | $changes = $this->getItemChanges($options); |
|
| 208 | 3 | return $changes->getChanges(); |
|
| 209 | } |
||
| 210 | /** |
||
| 211 | * Get TVShow episode crew |
||
| 212 | * @return \Generator|Results\Crew |
||
| 213 | */ |
||
| 214 | public function getCrew() : \Generator |
||
| 215 | { |
||
| 216 | $credit = new TVEpisodeCredit($this->tmdb, $this->tv_id, $this->season_number, $this->episode_number); |
||
| 217 | return $credit->getCrew(); |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Get TVShow episode cast |
||
| 222 | * @return \Generator|Results\Cast |
||
| 223 | */ |
||
| 224 | public function getCast() : \Generator |
||
| 225 | { |
||
| 226 | $cast = new TVEpisodeCredit($this->tmdb, $this->tv_id, $this->season_number, $this->episode_number); |
||
| 227 | return $cast->getCast(); |
||
| 228 | } |
||
| 229 | } |
||
| 230 |