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); |
||
29 | class TVNetwork extends Item implements TVNetworkInterface |
||
30 | { |
||
31 | use ElementTrait; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * @param TmdbInterface $tmdb |
||
36 | * @param int $network_id |
||
37 | * @param array $options |
||
38 | */ |
||
39 | 84 | public function __construct(TmdbInterface $tmdb, int $network_id, array $options = array()) |
|
45 | |||
46 | /** |
||
47 | * Get TV Network id |
||
48 | * @return int |
||
49 | */ |
||
50 | 9 | public function getId() : int |
|
54 | |||
55 | /** |
||
56 | * Get TV Network name |
||
57 | * @return string |
||
58 | */ |
||
59 | 6 | public function getName() : string |
|
66 | |||
67 | /** |
||
68 | * Get TV Network headquarters |
||
69 | * @return string |
||
70 | */ |
||
71 | 6 | public function getHeadquarters() : string |
|
78 | |||
79 | /** |
||
80 | * Get TV Network homepage |
||
81 | * @return string |
||
82 | */ |
||
83 | 6 | public function getHomepage() : string |
|
90 | |||
91 | /** |
||
92 | * Get TV Network origin country |
||
93 | * @return string |
||
94 | */ |
||
95 | 6 | public function getOriginCountry() : string |
|
102 | |||
103 | /** |
||
104 | * Alternative names list |
||
105 | * @return \Generator|Results\Name |
||
106 | */ |
||
107 | 12 | View Code Duplication | public function getAlternativeNames() : \Generator |
118 | |||
119 | /** |
||
120 | * Logos list |
||
121 | * @return \Generator|Results\Logo |
||
122 | */ |
||
123 | 36 | View Code Duplication | public function getLogos() : \Generator |
134 | } |
||
135 |
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.