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

People   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 231
Duplicated Lines 4.76 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 33
lcom 2
cbo 6
dl 11
loc 231
ccs 76
cts 76
cp 1
rs 9.3999
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAdult() 0 7 2
A getAlsoKnownAs() 0 7 2
A getBiography() 0 7 2
A getBirthday() 0 7 2
A getDeathday() 0 7 2
A getGender() 0 7 2
A getHomepage() 0 7 2
A getId() 0 7 2
A getImdbId() 0 7 2
A getName() 0 7 2
A getPlaceOfBirth() 0 7 2
A getPopularity() 0 7 2
A getProfilePath() 0 7 2
A getProfiles() 11 11 2
A getMoviesCast() 0 5 1
A getMoviesCrew() 0 5 1
A getTVShowCast() 0 5 1
A getTVShowCrew() 0 5 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 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
namespace VfacTmdb\Items;
15
16
use VfacTmdb\Abstracts\Item;
17
use VfacTmdb\Interfaces\Items\PeopleInterface;
18
use VfacTmdb\Traits\ElementTrait;
19
use VfacTmdb\Exceptions\TmdbException;
20
use VfacTmdb\Interfaces\TmdbInterface;
21
use VfacTmdb\Items\PeopleMovieCredit;
22
use VfacTmdb\Items\PeopleTVShowCredit;
23
use VfacTmdb\Results;
24
25
/**
26
 * People class
27
 * @package Tmdb
28
 * @author Vincent Faliès <[email protected]>
29
 * @copyright Copyright (c) 2017
30
 */
31
class People extends Item implements PeopleInterface
32
{
33
    use ElementTrait;
34
35
    /**
36
     * Constructor
37
     * @param TmdbInterface $tmdb
38
     * @param int $people_id
39
     * @param array $options
40
     * @throws TmdbException
41
     */
42 67
    public function __construct(TmdbInterface $tmdb, int $people_id, array $options = array())
43
    {
44 67
        parent::__construct($tmdb, $people_id, $options, 'person');
45
46 66
        $this->setElementTrait($this->data);
47 66
    }
48
49
    /**
50
     * Adult
51
     * @return bool
52
     */
53 2
    public function getAdult() : bool
54
    {
55 2
        if (isset($this->data->adult)) {
56 1
            return $this->data->adult;
57
        }
58 1
        return false;
59
    }
60
61
    /**
62
     * Alse Known as
63
     * @return array
64
     */
65 2
    public function getAlsoKnownAs() : array
66
    {
67 2
        if (isset($this->data->also_known_as)) {
68 1
            return $this->data->also_known_as;
69
        }
70 1
        return [];
71
    }
72
73
    /**
74
     * Biography
75
     * @return string
76
     */
77 2
    public function getBiography() : string
78
    {
79 2
        if (isset($this->data->biography)) {
80 1
            return $this->data->biography;
81
        }
82 1
        return '';
83
    }
84
85
    /**
86
     * Birthday
87
     * @return string
88
     */
89 2
    public function getBirthday() : string
90
    {
91 2
        if (isset($this->data->birthday)) {
92 1
            return $this->data->birthday;
93
        }
94 1
        return '';
95
    }
96
97
    /**
98
     * Deathday
99
     * @return string
100
     */
101 2
    public function getDeathday() : string
102
    {
103 2
        if (isset($this->data->deathday)) {
104 1
            return $this->data->deathday;
105
        }
106 1
        return '';
107
    }
108
109
    /**
110
     * Gender
111
     * @return int
112
     */
113 2
    public function getGender() : int
114
    {
115 2
        if (isset($this->data->gender)) {
116 1
            return $this->data->gender;
117
        }
118 1
        return 0;
119
    }
120
121
    /**
122
     * Homepage
123
     * @return string
124
     */
125 2
    public function getHomepage() : string
126
    {
127 2
        if (isset($this->data->homepage)) {
128 1
            return $this->data->homepage;
129
        }
130 1
        return '';
131
    }
132
133
    /**
134
     * Id
135
     * @return int
136
     */
137 3
    public function getId() : int
138
    {
139 3
        if (isset($this->data->id)) {
140 2
            return $this->data->id;
141
        }
142 1
        return 0;
143
    }
144
145
    /**
146
     * Imdb Id
147
     * @return string
148
     */
149 2
    public function getImdbId() : string
150
    {
151 2
        if (isset($this->data->imdb_id)) {
152 1
            return $this->data->imdb_id;
153
        }
154 1
        return '';
155
    }
156
157
    /**
158
     * Name
159
     * @return string
160
     */
161 2
    public function getName() : string
162
    {
163 2
        if (isset($this->data->name)) {
164 1
            return $this->data->name;
165
        }
166 1
        return '';
167
    }
168
169
    /**
170
     * Place of birth
171
     * @return string
172
     */
173 2
    public function getPlaceOfBirth() : string
174
    {
175 2
        if (isset($this->data->place_of_birth)) {
176 1
            return $this->data->place_of_birth;
177
        }
178 1
        return '';
179
    }
180
181
    /**
182
     * Popularity
183
     * @return float
184
     */
185 2
    public function getPopularity() : float
186
    {
187 2
        if (isset($this->data->popularity)) {
188 1
            return $this->data->popularity;
189
        }
190 1
        return 0;
191
    }
192
193
    /**
194
     * Image profile path
195
     * @return string
196
     */
197 2
    public function getProfilePath() : string
198
    {
199 2
        if (isset($this->data->profile_path)) {
200 1
            return $this->data->profile_path;
201
        }
202 1
        return '';
203
    }
204
205
    /**
206
     * Images Profiles
207
     * @return \Generator|Results\Image
208
     */
209 1 View Code Duplication
    public function getProfiles() : \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...
210
    {
211 1
        $params = [];
212 1
        $this->tmdb->checkOptionLanguage($this->params, $params);
213 1
        $data = $this->tmdb->getRequest('person/' . (int) $this->id . '/images', $params);
214
215 1
        foreach ($data->profiles as $b) {
216 1
            $image = new Results\Image($this->tmdb, $this->id, $b);
217 1
            yield $image;
218
        }
219 1
    }
220
221
    /**
222
     * Get movies cast
223
     * @return \Generator|Results\PeopleMovieCast
224
     */
225 9
    public function getMoviesCast() : \Generator
226
    {
227 9
        $credit = new PeopleMovieCredit($this->tmdb, $this->id);
228 9
        return $credit->getCast();
229
    }
230
231
    /**
232
     * Get movies crew
233
     * @return \Generator|Results\PeopleMovieCast
234
     */
235 10
    public function getMoviesCrew() : \Generator
236
    {
237 10
        $credit = new PeopleMovieCredit($this->tmdb, $this->id);
238 10
        return $credit->getCrew();
239
    }
240
241
242
    /**
243
     * Get TVShow cast
244
     * @return \Generator|Results\PeopleTVShowCast
245
     */
246 9
    public function getTVShowCast() : \Generator
247
    {
248 9
        $credit = new PeopleTVShowCredit($this->tmdb, $this->id);
249 9
        return $credit->getCast();
250
    }
251
252
    /**
253
     * Get TVShow crew
254
     * @return \Generator|Results\PeopleTVShowCast
255
     */
256 10
    public function getTVShowCrew() : \Generator
257
    {
258 10
        $credit = new PeopleTVShowCredit($this->tmdb, $this->id);
259 10
        return $credit->getCrew();
260
    }
261
}
262