Passed
Branch release/1.5.0 (d52397)
by vincent
02:35
created

TVEpisode   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 145
Duplicated Lines 14.48 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 27
lcom 1
cbo 8
dl 21
loc 145
ccs 58
cts 58
cp 1
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getId() 0 8 2
A getAirDate() 0 8 2
A getCrew() 11 13 3
A getEpisodeNumber() 0 8 2
A getGuestStars() 0 4 1
A getName() 0 8 2
A getNote() 0 8 2
A getNoteCount() 0 8 2
A getOverview() 0 8 2
A getProductionCode() 0 8 2
A getSeasonNumber() 0 8 2
A getStillPath() 0 8 2
A getPosters() 10 10 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
2
3
namespace vfalies\tmdb\Items;
4
5
use vfalies\tmdb\Abstracts\Item;
6
use vfalies\tmdb\Interfaces\Items\TVEpisodeInterface;
7
use vfalies\tmdb\Tmdb;
8
use vfalies\tmdb\Exceptions\NotYetImplementedException;
9
use vfalies\tmdb\Traits\ElementTrait;
10
use vfalies\tmdb\lib\Guzzle\Client as HttpClient;
11
use vfalies\tmdb\Results\Crew;
12
use vfalies\tmdb\Results\Image;
13
14
class TVEpisode extends Item implements TVEpisodeInterface
15
{
16
17
    use ElementTrait;
18
19
    protected $season_number;
20
    protected $episode_number;
21
22 22
    public function __construct(Tmdb $tmdb, $tv_id, $season_number, $episode_number, array $options = array())
23
    {
24 22
        parent::__construct($tmdb, $episode_number, $options, 'tv/'.$tv_id.'/'.$season_number);
25
26 22
        $this->season_number = $season_number;
27 22
        $this->episode_number = $episode_number;
28 22
    }
29
30
    /**
31
     * Get TV show id
32
     * @return int
33
     */
34 2
    public function getId()
35
    {
36 2
        if (isset($this->data->id))
37
        {
38 1
            return (int) $this->data->id;
39
        }
40 1
        return 0;
41
    }
42
43 2
    public function getAirDate()
44
    {
45 2
        if (isset($this->data->air_date))
46
        {
47 1
            return $this->data->air_date;
48
        }
49 1
        return '';
50
    }
51
52 1 View Code Duplication
    public function getCrew()
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...
53
    {
54 1
        if ( ! empty($this->data->crew))
55
        {
56 1
            foreach ($this->data->crew as $crew)
57
            {
58 1
                $crew->gender = null;
59
60 1
                $return = new Crew($this->tmdb, $crew);
61 1
                yield $return;
62
            }
63
        }
64 1
    }
65
66 2
    public function getEpisodeNumber()
67
    {
68 2
        if (isset($this->data->episode_number))
69
        {
70 1
            return $this->data->episode_number;
71
        }
72 1
        return 0;
73
    }
74
75
    /**
76
     * @codeCoverageIgnore
77
     * @throws NotYetImplementedException
78
     */
79
    public function getGuestStars()
80
    {
81
        throw new NotYetImplementedException;
82
    }
83
84 2
    public function getName()
85
    {
86 2
        if (isset($this->data->name))
87
        {
88 1
            return $this->data->name;
89
        }
90 1
        return '';
91
    }
92
93 2
    public function getNote()
94
    {
95 2
        if (isset($this->data->vote_average))
96
        {
97 1
            return $this->data->vote_average;
98
        }
99 1
        return 0;
100
    }
101
102 2
    public function getNoteCount()
103
    {
104 2
        if (isset($this->data->vote_count))
105
        {
106 1
            return (int) $this->data->vote_count;
107
        }
108 1
        return 0;
109
    }
110
111 2
    public function getOverview()
112
    {
113 2
        if (isset($this->data->overview))
114
        {
115 1
            return $this->data->overview;
116
        }
117 1
        return '';
118
    }
119
120 2
    public function getProductionCode()
121
    {
122 2
        if (isset($this->data->production_code))
123
        {
124 1
            return $this->data->production_code;
125
        }
126 1
        return '';
127
    }
128
129 2
    public function getSeasonNumber()
130
    {
131 2
        if (isset($this->data->season_number))
132
        {
133 1
            return (int) $this->data->season_number;
134
        }
135 1
        return 0;
136
    }
137
138 2
    public function getStillPath()
139
    {
140 2
        if (isset($this->data->still_path))
141
        {
142 1
            return $this->data->still_path;
143
        }
144 1
        return '';
145
    }
146
147 1 View Code Duplication
    public function getPosters()
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 1
        $data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/seasons/'.$this->season_number.'/episode/'.$this->episode_number.'/images', null, $this->params);
150
151 1
        foreach ($data->posters as $b)
152
        {
153 1
            $image = new Image($this->tmdb, $this->id, $b);
154 1
            yield $image;
155
        }
156 1
    }
157
158
}
159