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 |
||
5 | View Code Duplication | class TVShow extends Results |
|
|
|||
6 | { |
||
7 | |||
8 | protected $overview = null; |
||
9 | protected $first_air_date = null; |
||
10 | protected $original_name = null; |
||
11 | protected $name = null; |
||
12 | |||
13 | /** |
||
14 | * Constructor |
||
15 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
16 | * @param \stdClass $result |
||
17 | * @throws \Exception |
||
18 | */ |
||
19 | 12 | public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result) |
|
32 | |||
33 | /** |
||
34 | * Get tvshow ID |
||
35 | * @return int |
||
36 | */ |
||
37 | 1 | public function getId(): int |
|
41 | |||
42 | /** |
||
43 | * Get tvshow overview |
||
44 | * @return string |
||
45 | */ |
||
46 | 1 | public function getOverview(): string |
|
50 | |||
51 | /** |
||
52 | * Get tvshow first air date |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function getReleaseDate(): string |
|
59 | |||
60 | /** |
||
61 | * Get tvshow original name |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function getOriginalTitle(): string |
|
68 | |||
69 | /** |
||
70 | * Get tvshow name |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function getTitle(): string |
|
77 | |||
78 | } |
||
79 |
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.