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 SearchClient extends ContentClient |
|
|
|
|||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Get models & offers search result |
||
| 30 | * |
||
| 31 | * Returns models and offers of Yandex.Market service search result according to params. |
||
| 32 | * |
||
| 33 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/search-docpage/ |
||
| 34 | * |
||
| 35 | * @param array $params |
||
| 36 | * |
||
| 37 | * @return Models\ResponseSearchGet |
||
| 38 | */ |
||
| 39 | 1 | public function get($params = array()) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Get models & offers search by filters result |
||
| 52 | * |
||
| 53 | * Returns models and offers of Yandex.Market service search by filters result according to params. |
||
| 54 | * |
||
| 55 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/filter-id-docpage/ |
||
| 56 | * |
||
| 57 | * @param int $categoryId |
||
| 58 | * @param array $params |
||
| 59 | * |
||
| 60 | * @return Models\ResponseFilterCategoryGet |
||
| 61 | */ |
||
| 62 | 1 | public function getFilterCategory($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.