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 ModelClient extends ContentClient |
||
27 | { |
||
28 | /** |
||
29 | * Get model information |
||
30 | * |
||
31 | * Returns model of Yandex.Market service according to params. |
||
32 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-docpage/ |
||
33 | * |
||
34 | * @param int $modelId |
||
35 | * @param array $params |
||
36 | * |
||
37 | * @return Models\ResponseModelGet |
||
38 | */ |
||
39 | View Code Duplication | public function get($modelId, $params = array()) |
|
49 | |||
50 | /** |
||
51 | * Get model short information |
||
52 | * |
||
53 | * Returns short model of Yandex.Market service according to params. |
||
54 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-info-docpage/ |
||
55 | * |
||
56 | * @param int $modelId |
||
57 | * @param array $params |
||
58 | * |
||
59 | * @return Models\ResponseModelInfoGet |
||
60 | */ |
||
61 | public function getInfo($modelId, $params = array()) |
||
71 | |||
72 | /** |
||
73 | * Get offers in model |
||
74 | * |
||
75 | * Returns offers list represented in model of Yandex.Market service according to params. |
||
76 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-offers-docpage/ |
||
77 | * |
||
78 | * @param int $modelId |
||
79 | * @param array $params |
||
80 | * |
||
81 | * @return Models\ResponseModelOffersGet |
||
82 | */ |
||
83 | public function getOffers($modelId, $params = array()) |
||
93 | |||
94 | /** |
||
95 | * Get outlets of model |
||
96 | * |
||
97 | * Returns outlets list where model of Yandex.Market service represented according to params. |
||
98 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-outlets-docpage/ |
||
99 | * |
||
100 | * @param int $modelId |
||
101 | * @param array $params |
||
102 | * |
||
103 | * @return Models\ResponseModelOutletsGet |
||
104 | */ |
||
105 | public function getOutlets($modelId, $params = array()) |
||
115 | |||
116 | /** |
||
117 | * Get reviews of model |
||
118 | * |
||
119 | * Returns reviews list where model of Yandex.Market service represented. |
||
120 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-reviews-docpage/ |
||
121 | * |
||
122 | * @param int $modelId |
||
123 | * |
||
124 | * @return Models\ResponseModelReviewsGet |
||
125 | */ |
||
126 | public function getReviews($modelId) |
||
135 | |||
136 | /** |
||
137 | * Get model(-s) by name and params |
||
138 | * |
||
139 | * Returns model(-s) of Yandex.Market service by name and params. |
||
140 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-match-docpage/ |
||
141 | * |
||
142 | * @param array $params |
||
143 | * |
||
144 | * @return Models\ResponseModelMatchGet |
||
145 | */ |
||
146 | public function getMatch($params = array()) |
||
156 | |||
157 | /** |
||
158 | * Get opinions of model |
||
159 | * |
||
160 | * Returns opinions list of Yandex.Market service model. |
||
161 | * @see https://tech.yandex.ru/market/content-data/doc/dg/reference/model-id-opinion-docpage/ |
||
162 | * |
||
163 | * @param int $modelId |
||
164 | * @param array $params |
||
165 | * |
||
166 | * @return Models\ResponseModelOpinionsGet |
||
167 | */ |
||
168 | public function getOpinions($modelId, $params = array()) |
||
178 | } |
||
179 |
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.