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 | class CategoryClient extends ContentClient |
||
27 | { |
||
28 | /** |
||
29 | * Get Categories |
||
30 | * |
||
31 | * Returns categories list of Yandex.Market service according to params. |
||
32 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-docpage/ |
||
33 | * |
||
34 | * @param array $params |
||
35 | * |
||
36 | * @return Models\ResponseCategoryGetList |
||
37 | */ |
||
38 | public function getList($params = array()) |
||
48 | |||
49 | /** |
||
50 | * Get category information |
||
51 | * |
||
52 | * Returns category of Yandex.Market service according to params. |
||
53 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-docpage/ |
||
54 | * |
||
55 | * @param int $categoryId |
||
56 | * @param array $params |
||
57 | * |
||
58 | * @return Models\Category |
||
59 | */ |
||
60 | View Code Duplication | public function get($categoryId, $params = array()) |
|
70 | |||
71 | /** |
||
72 | * Get children categories |
||
73 | * |
||
74 | * Returns children categories list of Yandex.Market service according to params. |
||
75 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-children-docpage/ |
||
76 | * |
||
77 | * @param int $categoryId |
||
78 | * @param array $params |
||
79 | * |
||
80 | * @return Models\ResponseCategoryGetList |
||
81 | */ |
||
82 | public function getChildren($categoryId, $params = array()) |
||
92 | |||
93 | /** |
||
94 | * Get models in category |
||
95 | * |
||
96 | * Returns models list represented in category of Yandex.Market service according to params. |
||
97 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-model-docpage/ |
||
98 | * |
||
99 | * @param int $categoryId |
||
100 | * @param array $params |
||
101 | * |
||
102 | * @return Models\ResponseCategoryGetModels |
||
103 | */ |
||
104 | public function getModels($categoryId, $params = array()) |
||
114 | |||
115 | /** |
||
116 | * Get filters in category |
||
117 | * |
||
118 | * Returns filters list of models represented in category of Yandex.Market service according to params. |
||
119 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/category-id-filters-docpage/ |
||
120 | * |
||
121 | * @param int $categoryId |
||
122 | * @param array $params |
||
123 | * |
||
124 | * @return Models\ResponseCategoryGetFilters |
||
125 | */ |
||
126 | public function getFilters($categoryId, $params = array()) |
||
136 | } |
||
137 |
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.