Completed
Pull Request — master (#30)
by vincent
03:53
created

TVEpisode::getEpisodeNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
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\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
28
 */
29
class TVEpisode extends TVItem implements TVEpisodeInterface
30
{
31
    use TVEpisodeTrait;
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 24
    public function __construct(TmdbInterface $tmdb, int $tv_id, int $season_number, int $episode_number, array $options = array())
42
    {
43 24
        parent::__construct($tmdb, $episode_number, $options, 'tv/' . $tv_id . '/season/' . $season_number.'/episode');
44
45 24
        $this->season_number  = $season_number;
46 24
        $this->episode_number = $episode_number;
47 24
        $this->tv_id          = $tv_id;
48
49 24
        $this->setElementTrait($this->data);
50 24
        $this->setTVEpisodeTrait($tmdb, $this->data);
51 24
    }
52
53
    /**
54
     * Get TV show id
55
     * @return int
56
     */
57 3
    public function getId(): int
58
    {
59 3
        if (isset($this->data->id)) {
60 2
            return (int) $this->data->id;
61
        }
62 1
        return 0;
63
    }
64
65
    /**
66
     * Air date
67
     * @return string
68
     */
69 2
    public function getAirDate() : string
70
    {
71 2
        if (isset($this->data->air_date)) {
72 1
            return $this->data->air_date;
73
        }
74 1
        return '';
75
    }
76
77
    /**
78
     * Episode number
79
     * @return int
80
     */
81 2
    public function getEpisodeNumber() : int
82
    {
83 2
        if (isset($this->data->episode_number)) {
84 1
            return $this->data->episode_number;
85
        }
86 1
        return 0;
87
    }
88
89
    /**
90
     * Guests stars
91
     * @return \Generator|Results\Cast
92
     */
93 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...
94
    {
95 1
        if (isset($this->data->guest_stars)) {
96 1
            foreach ($this->data->guest_stars as $gs) {
97 1
                $gs->gender = null;
98 1
                $gs->cast_id = null;
99
100 1
                $star = new Results\Cast($this->tmdb, $gs);
101 1
                yield $star;
102
            }
103
        }
104 1
    }
105
106
    /**
107
     * Name
108
     * @return string
109
     */
110 2
    public function getName() : string
111
    {
112 2
        if (isset($this->data->name)) {
113 1
            return $this->data->name;
114
        }
115 1
        return '';
116
    }
117
118
    /**
119
     * Note
120
     * @return float
121
     */
122 2
    public function getNote() : float
123
    {
124 2
        if (isset($this->data->vote_average)) {
125 1
            return $this->data->vote_average;
126
        }
127 1
        return 0;
128
    }
129
130
    /**
131
     * Note count
132
     * @return int
133
     */
134 2
    public function getNoteCount() : int
135
    {
136 2
        if (isset($this->data->vote_count)) {
137 1
            return (int) $this->data->vote_count;
138
        }
139 1
        return 0;
140
    }
141
142
    /**
143
     * Overview
144
     * @return string
145
     */
146 2
    public function getOverview() : string
147
    {
148 2
        if (isset($this->data->overview)) {
149 1
            return $this->data->overview;
150
        }
151 1
        return '';
152
    }
153
154
    /**
155
     * Production code
156
     * @return string
157
     */
158 2
    public function getProductionCode() : string
159
    {
160 2
        if (isset($this->data->production_code)) {
161 1
            return $this->data->production_code;
162
        }
163 1
        return '';
164
    }
165
166
    /**
167
     * Season number
168
     * @return int
169
     */
170 2
    public function getSeasonNumber() : int
171
    {
172 2
        if (isset($this->data->season_number)) {
173 1
            return (int) $this->data->season_number;
174
        }
175 1
        return 0;
176
    }
177
178
    /**
179
     * Image still path
180
     * @return string
181
     */
182 2
    public function getStillPath() : string
183
    {
184 2
        if (isset($this->data->still_path)) {
185 1
            return $this->data->still_path;
186
        }
187 1
        return '';
188
    }
189
}
190