Passed
Branch account (d43697)
by vincent
02:17
created

TVEpisode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 17
cts 17
cp 1
rs 9.2
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 2
crap 1
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
12
 */
13
14
15
namespace VfacTmdb\Results;
16
17
use VfacTmdb\Abstracts;
18
use VfacTmdb\Results;
19
use VfacTmdb\Interfaces\Results\TVEpisodeResultsInterface;
20
use VfacTmdb\Traits\ElementTrait;
21
use VfacTmdb\Traits\TVEpisodeTrait;
22
use VfacTmdb\Interfaces\TmdbInterface;
23
24
/**
25
 * Class to manipulate a TV Episode result
26
 * @package Tmdb
27
 * @author Vincent Faliès <[email protected]>
28
 * @copyright Copyright (c) 2017
29
 */
30
class TVEpisode extends Abstracts\Results implements TVEpisodeResultsInterface
31
{
32
    use ElementTrait;
33
    use TVEpisodeTrait;
34
35
    /**
36
     * Episode number
37
     * @var int
38
     */
39
    protected $episode_number = 0;
40
    /**
41
     * Name
42
     * @var string
43
     */
44
    protected $name = '';
45
    /**
46
     * Air date
47
     * @var string
48
     */
49
    protected $air_date = null;
50
    /**
51
     * Season number
52
     * @var int
53
     */
54
    protected $season_number = 0;
55
    /**
56
     * Vote average
57
     * @var float
58
     */
59
    protected $vote_average = 0;
60
    /**
61
     * Vote count
62
     * @var int
63
     */
64
    protected $vote_count = 0;
65
    /**
66
     * Overview
67
     * @var string
68
     */
69
    protected $overview = '';
70
    /**
71
     * Production code
72
     * @var string
73
     */
74
    protected $production_code = '';
75
    /**
76
     * Image still path
77
     * @var string
78
     */
79
    protected $still_path = '';
80
    /**
81
     * Id
82
     * @var int
83
     */
84
    protected $id = null;
85
    /**
86
     * Guest stars
87
     * @var array
88
     */
89
    protected $guest_stars = [];
90
91
    /**
92
     * Constructor
93
     * @param TmdbInterface $tmdb
94
     * @param \stdClass $result
95
     * @throws \Exception
96
     */
97 21
    public function __construct(TmdbInterface $tmdb, \stdClass $result)
98
    {
99 21
        $result = $this->initResultObject($result);
100
101 21
        parent::__construct($tmdb, $result);
102
103
        // Populate data
104 21
        $this->id              = $this->data->id;
105 21
        $this->air_date        = $this->data->air_date;
106 21
        $this->season_number   = $this->data->season_number;
107 21
        $this->episode_number  = $this->data->episode_number;
108 21
        $this->name            = $this->data->name;
109 21
        $this->vote_average    = $this->data->vote_average;
110 21
        $this->vote_count      = $this->data->vote_count;
111 21
        $this->overview        = $this->data->overview;
112 21
        $this->production_code = $this->data->production_code;
113 21
        $this->still_path      = $this->data->still_path;
114 21
        $this->guest_stars     = $this->data->guest_stars;
115
116 21
        $this->setElementTrait($this->data);
117 21
        $this->setTVEpisodeTrait($tmdb, $this->data);
118 21
    }
119
120
    /**
121
     * initResultObject
122
     * @param  \stdClass  $result
123
     * @return \stdClass
124
     */
125 21
    private function initResultObject(\stdClass $result) : \stdClass
126
    {
127 21
        if (!isset($result->overview)) {
128 1
            $result->overview = null;
129
        }
130 21
        if (!isset($result->production_code)) {
131 1
            $result->production_code = null;
132
        }
133 21
        if (!isset($result->guest_stars)) {
134 1
            $result->guest_stars = null;
135
        }
136 21
        return $result;
137
    }
138
139
    /**
140
     * Air date
141
     * @return string
142
     */
143 1
    public function getAirDate() : string
144
    {
145 1
        return $this->air_date;
146
    }
147
148
    /**
149
     * Episode number
150
     * @return int
151
     */
152 1
    public function getEpisodeNumber() : int
153
    {
154 1
        return (int) $this->episode_number;
155
    }
156
157
    /**
158
     * Guests stars
159
     * @return \Generator|Results\Cast
160
     */
161 1 View Code Duplication
    public function getGuestStars() : \Generator
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...
162
    {
163 1
        if (isset($this->guest_stars)) {
164 1
            foreach ($this->guest_stars as $gs) {
165 1
                $gs->gender = null;
166 1
                $gs->cast_id = null;
167
168 1
                $star = new Results\Cast($this->tmdb, $gs);
169 1
                yield $star;
170
            }
171
        }
172 1
    }
173
174
    /**
175
     * Id
176
     * @return int
177
     */
178 1
    public function getId() : int
179
    {
180 1
        return (int) $this->id;
181
    }
182
183
    /**
184
     * Name
185
     * @return string
186
     */
187 1
    public function getName() : string
188
    {
189 1
        return $this->name;
190
    }
191
192
    /**
193
     * Note
194
     * @return float
195
     */
196 1
    public function getNote() : float
197
    {
198 1
        return $this->vote_average;
199
    }
200
201
    /**
202
     * Note count
203
     * @return int
204
     */
205 1
    public function getNoteCount() : int
206
    {
207 1
        return (int) $this->vote_count;
208
    }
209
210
    /**
211
     * Overview
212
     * @return string
213
     */
214 1
    public function getOverview() : string
215
    {
216 1
        return $this->overview;
217
    }
218
219
    /**
220
     * Production code
221
     * @return string
222
     */
223 1
    public function getProductionCode() : string
224
    {
225 1
        return $this->production_code;
226
    }
227
228
    /**
229
     * Season number
230
     * @return int
231
     */
232 1
    public function getSeasonNumber() : int
233
    {
234 1
        return (int) $this->season_number;
235
    }
236
237
    /**
238
     * Image still path
239
     * @return string
240
     */
241 1
    public function getStillPath() : string
242
    {
243 1
        return $this->still_path;
244
    }
245
}
246