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 Company extends Item implements CompanyInterface |
||
| 30 | { |
||
| 31 | use ElementTrait; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Constructor |
||
| 35 | * @param TmdbInterface $tmdb |
||
| 36 | * @param int $company_id |
||
| 37 | * @param array $options |
||
| 38 | */ |
||
| 39 | 15 | public function __construct(TmdbInterface $tmdb, int $company_id, array $options = array()) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Company description |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 2 | public function getDescription() : string |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Company Head quarters |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 2 | public function getHeadQuarters() : string |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Company Homepage |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | 2 | public function getHomePage() : string |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Company Id |
||
| 84 | * @return int |
||
| 85 | */ |
||
| 86 | 3 | public function getId() : int |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Company image logo path |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | 2 | public function getLogoPath() : string |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Company name |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | 2 | public function getName() : string |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Company movies list |
||
| 120 | * @return \Generator|Results\Movie |
||
| 121 | */ |
||
| 122 | 1 | View Code Duplication | public function getMovies() : \Generator |
| 133 | } |
||
| 134 |
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.