Passed
Push — master ( fc0106...465d67 )
by vincent
51s
created

TVEpisode::getPosters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
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\TVEpisodeInterface;
19
use vfalies\tmdb\Exceptions\NotYetImplementedException;
20
use vfalies\tmdb\Traits\ElementTrait;
21
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
22
use vfalies\tmdb\Results\Image;
23
use vfalies\tmdb\Results\Cast;
24
use vfalies\tmdb\Traits\TVEpisodeTrait;
25
use vfalies\tmdb\Interfaces\TmdbInterface;
26
27
/**
28
 * TVEpisode class
29
 * @package Tmdb
30
 * @author Vincent Faliès <[email protected]>
31
 * @copyright Copyright (c) 2017
32
 */
33
class TVEpisode extends Item implements TVEpisodeInterface
34
{
35
36
    use ElementTrait;
37
    use TVEpisodeTrait;
38
39
    /**
40
     * Season number
41
     * @var int
42
     */
43
    protected $season_number;
44
    /**
45
     * Episode number
46
     * @var int
47
     */
48
    protected $episode_number;
49
50
    /**
51
     * Constructor
52
     * @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb
53
     * @param int $tv_id
54
     * @param int $season_number
55
     * @param int $episode_number
56
     * @param array $options
57
     */
58 23
    public function __construct(TmdbInterface $tmdb, $tv_id, $season_number, $episode_number, array $options = array())
59
    {
60 23
        parent::__construct($tmdb, $episode_number, $options, 'tv/' . $tv_id . '/' . $season_number);
61
62 23
        $this->season_number = $season_number;
63 23
        $this->episode_number = $episode_number;
64 23
    }
65
66
    /**
67
     * Get TV show id
68
     * @return int
69
     */
70 2
    public function getId()
71
    {
72 2
        if (isset($this->data->id))
73
        {
74 1
            return (int) $this->data->id;
75
        }
76 1
        return 0;
77
    }
78
79
    /**
80
     * Air date
81
     * @return string
82
     */
83 2
    public function getAirDate()
84
    {
85 2
        if (isset($this->data->air_date))
86
        {
87 1
            return $this->data->air_date;
88
        }
89 1
        return '';
90
    }
91
92
    /**
93
     * Episode number
94
     * @return int
95
     */
96 2
    public function getEpisodeNumber()
97
    {
98 2
        if (isset($this->data->episode_number))
99
        {
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
110
    {
111 1
        if (isset($this->data->guest_stars))
112
        {
113 1
            foreach ($this->data->guest_stars as $gs)
114
            {
115 1
                $gs->gender = null;
116 1
                $gs->cast_id = null;
117
118 1
                $star = new Cast($this->tmdb, $gs);
119 1
                yield $star;
120
            }
121
        }
122 1
    }
123
124
    /**
125
     * Name
126
     * @return string
127
     */
128 2
    public function getName()
129
    {
130 2
        if (isset($this->data->name))
131
        {
132 1
            return $this->data->name;
133
        }
134 1
        return '';
135
    }
136
137
    /**
138
     * Note
139
     * @return float
140
     */
141 2
    public function getNote()
142
    {
143 2
        if (isset($this->data->vote_average))
144
        {
145 1
            return $this->data->vote_average;
146
        }
147 1
        return 0;
148
    }
149
150
    /**
151
     * Note count
152
     * @return int
153
     */
154 2
    public function getNoteCount()
155
    {
156 2
        if (isset($this->data->vote_count))
157
        {
158 1
            return (int) $this->data->vote_count;
159
        }
160 1
        return 0;
161
    }
162
163
    /**
164
     * Overview
165
     * @return string
166
     */
167 2
    public function getOverview()
168
    {
169 2
        if (isset($this->data->overview))
170
        {
171 1
            return $this->data->overview;
172
        }
173 1
        return '';
174
    }
175
176
    /**
177
     * Production code
178
     * @return string
179
     */
180 2
    public function getProductionCode()
181
    {
182 2
        if (isset($this->data->production_code))
183
        {
184 1
            return $this->data->production_code;
185
        }
186 1
        return '';
187
    }
188
189
    /**
190
     * Season number
191
     * @return int
192
     */
193 2
    public function getSeasonNumber()
194
    {
195 2
        if (isset($this->data->season_number))
196
        {
197 1
            return (int) $this->data->season_number;
198
        }
199 1
        return 0;
200
    }
201
202
    /**
203
     * Image still path
204
     * @return string
205
     */
206 2
    public function getStillPath()
207
    {
208 2
        if (isset($this->data->still_path))
209
        {
210 1
            return $this->data->still_path;
211
        }
212 1
        return '';
213
    }
214
215
    /**
216
     * Image posters
217
     * @return \Generator|Results\Image
218
     */
219 1 View Code Duplication
    public function getPosters()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
220
    {
221 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);
222
223 1
        foreach ($data->posters as $b)
224
        {
225 1
            $image = new Image($this->tmdb, $this->id, $b);
226 1
            yield $image;
227
        }
228 1
    }
229
230
}
231