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

TVShow   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 214
Duplicated Lines 15.89 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 6
dl 34
loc 214
ccs 81
cts 81
cp 1
rs 9.6
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getGenres() 0 7 2
A getNote() 0 7 2
A getNumberEpisodes() 0 7 2
A getNumberSeasons() 0 7 2
A getOriginalTitle() 0 7 2
A getOverview() 0 7 2
A getReleaseDate() 0 7 2
A getStatus() 0 7 2
A getTitle() 0 7 2
A getSeasons() 0 9 3
A getNetworks() 0 12 3
A getBackdrops() 11 11 2
A getPosters() 11 11 2
A getSimilar() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Item;
18
use VfacTmdb\Interfaces\Items\TVShowInterface;
19
use VfacTmdb\Traits\ElementTrait;
20
use VfacTmdb\Interfaces\TmdbInterface;
21
use VfacTmdb\Results;
22
23
/**
24
 * TVShow class
25
 * @package Tmdb
26
 * @author Vincent Faliès <[email protected]>
27
 * @copyright Copyright (c) 2017
28
 */
29
class TVShow extends Item implements TVShowInterface
30
{
31
    use ElementTrait;
32
33
    /**
34
     * Constructor
35
     * @param TmdbInterface $tmdb
36
     * @param int $tv_id
37
     * @param array $options
38
     */
39 34
    public function __construct(TmdbInterface $tmdb, int $tv_id, array $options = array())
40
    {
41 34
        parent::__construct($tmdb, $tv_id, $options, 'tv');
42
43 33
        $this->setElementTrait($this->data);
44 33
    }
45
46
    /**
47
     * Get TV show id
48
     * @return int
49
     */
50 1
    public function getId() : int
51
    {
52 1
        return $this->id;
53
    }
54
55
    /**
56
     * Get TVSHow genres
57
     * @return array
58
     */
59 2
    public function getGenres() : array
60
    {
61 2
        if (isset($this->data->genres)) {
62 1
            return $this->data->genres;
63
        }
64 1
        return [];
65
    }
66
67
    /**
68
     * Get TVshow note
69
     *  @return float
70
     */
71 2
    public function getNote() : float
72
    {
73 2
        if (isset($this->data->vote_average)) {
74 1
            return $this->data->vote_average;
75
        }
76 1
        return 0;
77
    }
78
79
    /**
80
     * Get TVshow number of episodes
81
     * @return int
82
     */
83 2
    public function getNumberEpisodes() : int
84
    {
85 2
        if (isset($this->data->number_of_episodes)) {
86 1
            return $this->data->number_of_episodes;
87
        }
88 1
        return 0;
89
    }
90
91
    /**
92
     * Get TVShow number of seasons
93
     * @return int
94
     */
95 2
    public function getNumberSeasons() : int
96
    {
97 2
        if (isset($this->data->number_of_seasons)) {
98 1
            return $this->data->number_of_seasons;
99
        }
100 1
        return 0;
101
    }
102
103
    /**
104
     * Get TVShow original title
105
     * @return string
106
     */
107 2
    public function getOriginalTitle() : string
108
    {
109 2
        if (isset($this->data->original_name)) {
110 1
            return $this->data->original_name;
111
        }
112 1
        return '';
113
    }
114
115
    /**
116
     * Get TVShow overview
117
     * @return string
118
     */
119 2
    public function getOverview() : string
120
    {
121 2
        if (isset($this->data->overview)) {
122 1
            return $this->data->overview;
123
        }
124 1
        return '';
125
    }
126
127
    /**
128
     * Get TVShow release date
129
     * @return string
130
     */
131 2
    public function getReleaseDate() : string
132
    {
133 2
        if (isset($this->data->first_air_date)) {
134 1
            return $this->data->first_air_date;
135
        }
136 1
        return '';
137
    }
138
139
    /**
140
     * Get TVShow status
141
     * @return string
142
     */
143 2
    public function getStatus() : string
144
    {
145 2
        if (isset($this->data->status)) {
146 1
            return $this->data->status;
147
        }
148 1
        return '';
149
    }
150
151
    /**
152
     * Get TVShow title
153
     * @return string
154
     */
155 2
    public function getTitle() : string
156
    {
157 2
        if (isset($this->data->name)) {
158 1
            return $this->data->name;
159
        }
160 1
        return '';
161
    }
162
163
    /**
164
     * Get TVShow seasons
165
     * @return \Generator|Results\TVSeason
166
     */
167 6
    public function getSeasons() : \Generator
168
    {
169 6
        if (!empty($this->data->seasons)) {
170 5
            foreach ($this->data->seasons as $season) {
171 5
                $season = new Results\TVSeason($this->tmdb, $season);
172 5
                yield $season;
173
            }
174
        }
175 2
    }
176
177
    /**
178
     * Get TVShow networks
179
     * @return \Generator|\stdClass
180
     */
181 1
    public function getNetworks() : \Generator
182
    {
183 1
        if (!empty($this->data->networks)) {
184 1
            foreach ($this->data->networks as $network) {
185 1
                $n       = new \stdClass();
186 1
                $n->id   = $network->id;
187 1
                $n->name = $network->name;
188
189 1
                yield $n;
190
            }
191
        }
192 1
    }
193
194
    /**
195
     * Backdrops list
196
     * @return \Generator|Results\Image
197
     */
198 1 View Code Duplication
    public function getBackdrops() : \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...
199
    {
200 1
        $params = [];
201 1
        $this->tmdb->checkOptionLanguage($this->params, $params);
202 1
        $data = $this->tmdb->getRequest('tv/' . (int) $this->id . '/images', $params);
203
204 1
        foreach ($data->backdrops as $b) {
205 1
            $image = new Results\Image($this->tmdb, $this->id, $b);
206 1
            yield $image;
207
        }
208 1
    }
209
210
    /**
211
     * Posters list
212
     * @return \Generator|Results\Image
213
     */
214 1 View Code Duplication
    public function getPosters() : \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...
215
    {
216 1
        $params = [];
217 1
        $this->tmdb->checkOptionLanguage($this->params, $params);
218 1
        $data = $this->tmdb->getRequest('tv/' . (int) $this->id . '/images', $params);
219
220 1
        foreach ($data->posters as $b) {
221 1
            $image = new Results\Image($this->tmdb, $this->id, $b);
222 1
            yield $image;
223
        }
224 1
    }
225
226
    /**
227
     * Get Similar TVShow
228
     * @return \Generator|Results\TVShow
229
     */
230 1 View Code Duplication
    public function getSimilar() : \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...
231
    {
232 1
        $params = [];
233 1
        $this->tmdb->checkOptionLanguage($this->params, $params);
234 1
        $this->tmdb->checkOptionPage($this->params, $params);
235 1
        $similar = $this->tmdb->getRequest('tv/' . (int) $this->id . '/similar', $params);
236
237 1
        foreach ($similar->results as $t) {
238 1
            $tvshow = new Results\TVShow($this->tmdb, $t);
239 1
            yield $tvshow;
240
        }
241 1
    }
242
}
243