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 |
||
26 | View Code Duplication | class PeopleTVShowCast extends Results |
|
|
|||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Character name |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $character = null; |
||
34 | |||
35 | /** |
||
36 | * Credit Id |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $credit_id = null; |
||
40 | |||
41 | /** |
||
42 | * name |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $name = null; |
||
46 | |||
47 | /** |
||
48 | * Image poster path |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $poster_path = null; |
||
52 | |||
53 | /** |
||
54 | * original name |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $original_name = null; |
||
58 | |||
59 | /** |
||
60 | * First air date |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $first_air_date = null; |
||
64 | |||
65 | /** |
||
66 | * Id |
||
67 | * @var int |
||
68 | */ |
||
69 | protected $id = null; |
||
70 | |||
71 | /** |
||
72 | * Episode count |
||
73 | * @var int |
||
74 | */ |
||
75 | protected $episode_count = null; |
||
76 | |||
77 | /** |
||
78 | * Constructor |
||
79 | * @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb |
||
80 | * @param \stdClass $result |
||
81 | */ |
||
82 | 9 | public function __construct(TmdbInterface $tmdb, \stdClass $result) |
|
95 | |||
96 | /** |
||
97 | * Get Id |
||
98 | * @return int |
||
99 | */ |
||
100 | 1 | public function getId() |
|
104 | |||
105 | /** |
||
106 | * Get credit Id |
||
107 | * @return string |
||
108 | */ |
||
109 | 1 | public function getCreditId() |
|
113 | |||
114 | /** |
||
115 | * Get character name |
||
116 | * @return string |
||
117 | */ |
||
118 | 1 | public function getCharacter() |
|
122 | |||
123 | /** |
||
124 | * Get name |
||
125 | * @return string |
||
126 | */ |
||
127 | 1 | public function getName() |
|
131 | |||
132 | /** |
||
133 | * Get original name |
||
134 | * @return string |
||
135 | */ |
||
136 | 1 | public function getOriginalName() |
|
140 | |||
141 | /** |
||
142 | * Get poster path |
||
143 | * @return string |
||
144 | */ |
||
145 | 1 | public function getPosterPath() |
|
149 | |||
150 | /** |
||
151 | * Get first air date |
||
152 | * @return string |
||
153 | */ |
||
154 | 1 | public function getFirstAirDate() |
|
158 | |||
159 | /** |
||
160 | * Episode count |
||
161 | * @return boolean |
||
162 | */ |
||
163 | 1 | public function getEpisodeCount() |
|
167 | |||
168 | } |
||
169 |
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.