Passed
Push — master ( 585494...856ecb )
by vincent
03:23 queued 12s
created

TVSeason::getCast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Exceptions\TmdbException;
19
use VfacTmdb\Interfaces\Items\TVSeasonInterface;
20
use VfacTmdb\Results;
21
use VfacTmdb\Interfaces\TmdbInterface;
22
23
/**
24
 * TVSeason class
25
 * @package Tmdb
26
 * @author Vincent Faliès <[email protected]>
27
 * @copyright Copyright (c) 2017-2021
28
 */
29
class TVSeason extends TVItem implements TVSeasonInterface
30
{
31
32
    /**
33
     * Constructor
34
     * @param TmdbInterface $tmdb
35
     * @param int $tv_id
36
     * @param int $season_number
37
     * @param array $options
38
     * @throws TmdbException
39
     */
40 108
    public function __construct(TmdbInterface $tmdb, int $tv_id, int $season_number, array $options = array())
41
    {
42 108
        parent::__construct($tmdb, $season_number, $options, 'tv/' . $tv_id . '/season');
43
44 108
        $this->season_number = $season_number;
45 108
        $this->tv_id         = $tv_id;
46
47 108
        $this->setElementTrait($this->data);
48 108
    }
49
50
    /**
51
     * Id
52
     * @return int
53
     */
54 12
    public function getId() : int
55
    {
56 12
        if (!empty($this->data->id)) {
57 9
            return (int) $this->data->id;
58
        }
59 3
        return 0;
60
    }
61
62
    /**
63
     * Air date
64
     * @return string
65
     */
66 6
    public function getAirDate() : string
67
    {
68 6
        if (!empty($this->data->air_date)) {
69 3
            return $this->data->air_date;
70
        }
71 3
        return '';
72
    }
73
74
    /**
75
     * Episode count
76
     * @return int
77
     */
78 6
    public function getEpisodeCount() : int
79
    {
80 6
        if (!empty($this->data->episodes)) {
81 3
            return count($this->data->episodes);
82
        }
83 3
        return 0;
84
    }
85
86
    /**
87
     * Season number
88
     * @return int
89
     */
90 6
    public function getSeasonNumber() : int
91
    {
92 6
        if (!empty($this->data->season_number)) {
93 3
            return (int) $this->data->season_number;
94
        }
95 3
        return 0;
96
    }
97
98
    /**
99
     * Episodes list
100
     * @return \Generator|Results\TVEpisode
101
     */
102 63
    public function getEpisodes() : \Generator
103
    {
104 63
        if (!empty($this->data->episodes)) {
105 60
            foreach ($this->data->episodes as $episode) {
106 60
                $episode = new Results\TVEpisode($this->tmdb, $episode);
107 60
                yield $episode;
108
            }
109
        }
110 6
    }
111
112
    /**
113
     * Name
114
     * @return string
115
     */
116 6
    public function getName() : string
117
    {
118 6
        if (!empty($this->data->name)) {
119 3
            return $this->data->name;
120
        }
121 3
        return '';
122
    }
123
124
    /**
125
     * Overview
126
     * @return string
127
     */
128 6
    public function getOverview() : string
129
    {
130 6
        if (!empty($this->data->overview)) {
131 3
            return $this->data->overview;
132
        }
133 3
        return '';
134
    }
135
136
    /**
137
     * Get the underlying ItemChanges object for this Item
138
     * @param array $options Array of options for the request
139
     * @return TVSeasonItemChanges
140
     */
141 3
    public function getItemChanges(array $options = array()) : TVSeasonItemChanges
142
    {
143 3
        return new TVSeasonItemChanges($this->tmdb, $this->getId(), $options);
144
    }
145
146
    /**
147
     * Get this Item's Changes
148
     * @param array $options Array of options for the request
149
     * @return \Generator
150
     */
151 3
    public function getChanges(array $options = array()) : \Generator
152
    {
153 3
        $changes = $this->getItemChanges($options);
154 3
        return $changes->getChanges();
155
    }
156
157
158
    /**
159
     * Get TVShow Season crew
160
     * @return \Generator|Results\Crew
161
     */
162
    public function getCrew() : \Generator
163
    {
164
        $credit = new TVSeasonCredit($this->tmdb, $this->tv_id, $this->season_number);
165
        return $credit->getCrew();
166
    }
167
168
    /**
169
     * Get TVShow Season cast
170
     * @return \Generator|Results\Cast
171
     */
172
    public function getCast() : \Generator
173
    {
174
        $cast = new TVSeasonCredit($this->tmdb, $this->tv_id, $this->season_number);
175
        return $cast->getCast();
176
    }
177
}
178