Completed
Pull Request — master (#2)
by
unknown
08:22
created

TVShow   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 208
Duplicated Lines 23.56 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 30
lcom 1
cbo 2
dl 49
loc 208
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 17 17 2
A getId() 0 4 1
A getBackdrop() 16 16 4
A getGenres() 0 8 2
A getNote() 0 8 2
A getNumberEpisodes() 0 8 2
A getNumberSeasons() 0 8 2
A getOriginalTitle() 0 8 2
A getOverview() 0 8 2
A getPoster() 16 16 4
A getReleaseDate() 0 8 2
A getStatus() 0 8 2
A getTitle() 0 8 2
A getSeasons() 0 4 1

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
2
3
namespace vfalies\tmdb;
4
5
class TVShow implements Interfaces\TVShowInterface
6
{
7
8
    private $id   = null;
9
    private $tmdb = null;
10
    private $conf = null;
11
    private $data = null;
12
13 28 View Code Duplication
    public function __construct(Tmdb $tmdb, int $tv_id, array $options = array())
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...
14
    {
15
        try
16
        {
17 28
            $this->id   = $tv_id;
18 28
            $this->tmdb = $tmdb;
19 28
            $this->conf = $this->tmdb->getConfiguration();
20
21
            // Get tvshow details
22 28
            $params     = $this->tmdb->checkOptions($options);
23 28
            $this->data = $this->tmdb->sendRequest(new CurlRequest(), 'tv/' . (int) $tv_id, null, $params);
24
        }
25 1
        catch (\Exception $ex)
26
        {
27 1
            throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
28
        }
29 27
    }
30
31
    /**
32
     * Get TV show id
33
     * @return int
34
     */
35 1
    public function getId(): int
36
    {
37 1
        return $this->id;
38
    }
39
40
    /**
41
     * Get TVShow backdrop
42
     * @param string $size
43
     * @return string
44
     * @throws \Exception
45
     */
46 4 View Code Duplication
    public function getBackdrop(string $size = 'w780'): string
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...
47
    {
48 4
        if (isset($this->data->backdrop_path))
49
        {
50 3
            if (!isset($this->conf->images->base_url))
51
            {
52 1
                throw new \Exception('base_url configuration not found');
53
            }
54 2
            if (!in_array($size, $this->conf->images->backdrop_sizes))
55
            {
56 1
                throw new \Exception('Incorrect backdrop size : ' . $size);
57
            }
58 1
            return $this->conf->images->base_url . $size . $this->data->backdrop_path;
59
        }
60 1
        return '';
61
    }
62
63
    /**
64
     * Get TVSHow genres
65
     * @return array
66
     */
67 2
    public function getGenres(): array
68
    {
69 2
        if (isset($this->data->genres))
70
        {
71 1
            return $this->data->genres;
72
        }
73 1
        return [];
74
    }
75
76
    /**
77
     * Get TVshow note
78
     *  @return float
79
     */
80 2
    public function getNote(): float
81
    {
82 2
        if (isset($this->data->vote_average))
83
        {
84 1
            return $this->data->vote_average;
85
        }
86 1
        return 0;
87
    }
88
89
    /**
90
     * Get TVshow number of episodes
91
     * @return int
92
     */
93 2
    public function getNumberEpisodes(): int
94
    {
95 2
        if (isset($this->data->number_of_episodes))
96
        {
97 1
            return $this->data->number_of_episodes;
98
        }
99 1
        return 0;
100
    }
101
102
    /**
103
     * Get TVShow number of seasons
104
     * @return int
105
     */
106 2
    public function getNumberSeasons(): int
107
    {
108 2
        if (isset($this->data->number_of_seasons))
109
        {
110 1
            return $this->data->number_of_seasons;
111
        }
112 1
        return 0;
113
    }
114
115
    /**
116
     * Get TVShow original title
117
     * @return string
118
     */
119 2
    public function getOriginalTitle(): string
120
    {
121 2
        if (isset($this->data->original_name))
122
        {
123 1
            return $this->data->original_name;
124
        }
125 1
        return '';
126
    }
127
128
    /**
129
     * Get TVShow overview
130
     * @return string
131
     */
132 2
    public function getOverview(): string
133
    {
134 2
        if (isset($this->data->overview))
135
        {
136 1
            return $this->data->overview;
137
        }
138 1
        return '';
139
    }
140
141
    /**
142
     * Get TVShow poster
143
     * @param string $size
144
     * @return string
145
     * @throws \Exception
146
     */
147 4 View Code Duplication
    public function getPoster(string $size = 'w185'): string
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...
148
    {
149 4
        if (isset($this->data->poster_path))
150
        {
151 3
            if (!isset($this->conf->images->base_url))
152
            {
153 1
                throw new \Exception('base_url configuration not found');
154
            }
155 2
            if (!in_array($size, $this->conf->images->poster_sizes))
156
            {
157 1
                throw new \Exception('Incorrect poster size : ' . $size);
158
            }
159 1
            return $this->conf->images->base_url . $size . $this->data->poster_path;
160
        }
161 1
        return '';
162
    }
163
164
    /**
165
     * Get TVShow release date
166
     * @return string
167
     */
168 2
    public function getReleaseDate(): string
169
    {
170 2
        if (isset($this->data->first_air_date))
171
        {
172 1
            return $this->data->first_air_date;
173
        }
174 1
        return '';
175
    }
176
177
    /**
178
     * Get TVShow status
179
     * @return string
180
     */
181 2
    public function getStatus(): string
182
    {
183 2
        if (isset($this->data->status))
184
        {
185 1
            return $this->data->status;
186
        }
187 1
        return '';
188
    }
189
190
    /**
191
     * Get TVShow title
192
     * @return string
193
     */
194 2
    public function getTitle(): string
195
    {
196 2
        if (isset($this->data->name))
197
        {
198 1
            return $this->data->name;
199
        }
200 1
        return '';
201
    }
202
203
    /**
204
     * Get TVShow seasons
205
     * @return \Generator
206
     * @throws \Exception
207
     */
208
    public function getSeasons() : \Generator
209
    {
210
        throw new \Exception('Not yet implemented');
211
    }
212
}
213