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 Movie extends Results |
|
|
|||
6 | { |
||
7 | protected $overview = null; |
||
8 | protected $release_date = null; |
||
9 | protected $original_title = null; |
||
10 | protected $title = null; |
||
11 | |||
12 | /** |
||
13 | * Constructor |
||
14 | * @param \vfalies\tmdb\Tmdb $tmdb |
||
15 | * @param \stdClass $result |
||
16 | * @throws \Exception |
||
17 | */ |
||
18 | 13 | public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result) |
|
31 | |||
32 | /** |
||
33 | * Get movie ID |
||
34 | * @return int |
||
35 | */ |
||
36 | 1 | public function getId(): int |
|
40 | |||
41 | /** |
||
42 | * Get movie overview |
||
43 | * @return string |
||
44 | */ |
||
45 | 1 | public function getOverview(): string |
|
49 | |||
50 | /** |
||
51 | * Get movie release date |
||
52 | * @return string |
||
53 | */ |
||
54 | 1 | public function getReleaseDate(): string |
|
58 | |||
59 | /** |
||
60 | * Get movie original title |
||
61 | * @return string |
||
62 | */ |
||
63 | 1 | public function getOriginalTitle(): string |
|
67 | |||
68 | /** |
||
69 | * Get movie title |
||
70 | * @return string |
||
71 | */ |
||
72 | 1 | public function getTitle(): string |
|
76 | |||
77 | } |
||
78 |
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.