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 PopularClient extends ContentClient |
|
|
|
|||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Get popular models |
||
| 30 | * |
||
| 31 | * Returns popular models of Yandex.Market service according to params. |
||
| 32 | * |
||
| 33 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/popular-docpage/ |
||
| 34 | * |
||
| 35 | * @param array $params |
||
| 36 | * |
||
| 37 | * @return Models\ResponsePopularModelsGet |
||
| 38 | */ |
||
| 39 | 1 | public function getModels($params = array()) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Get popular category models |
||
| 52 | * |
||
| 53 | * Returns popular category models of Yandex.Market service according to params. |
||
| 54 | * |
||
| 55 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/popular-category-id-docpage/ |
||
| 56 | * |
||
| 57 | * @param int $categoryId |
||
| 58 | * @param array $params |
||
| 59 | * |
||
| 60 | * @return Models\ResponsePopularCategoryModelsGet |
||
| 61 | */ |
||
| 62 | 1 | public function getCategoryModels($categoryId, $params = array()) |
|
| 72 | } |
||
| 73 |
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.