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 |
||
35 | class SearchMappingService { |
||
36 | |||
37 | /** @var ConfigService */ |
||
38 | private $configService; |
||
39 | |||
40 | /** @var MiscService */ |
||
41 | private $miscService; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * MappingService constructor. |
||
46 | * |
||
47 | * @param ConfigService $configService |
||
48 | * @param MiscService $miscService |
||
49 | */ |
||
50 | public function __construct(ConfigService $configService, MiscService $miscService) { |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @param IFullTextSearchProvider $provider |
||
58 | * @param DocumentAccess $access |
||
59 | * @param SearchRequest $request |
||
60 | * |
||
61 | * @return array |
||
|
|||
62 | * @throws ConfigurationException |
||
63 | */ |
||
64 | public function generateSearchQuery( |
||
71 | |||
72 | |||
73 | /** |
||
74 | * @param IFullTextSearchProvider $provider |
||
75 | * @param DocumentAccess $access |
||
76 | * @param SearchRequest $request |
||
77 | * |
||
78 | * @return array |
||
79 | * @throws ConfigurationException |
||
80 | */ |
||
81 | public function generateSearchQueryParams( |
||
105 | |||
106 | |||
107 | /** |
||
108 | * @param SearchRequest $request |
||
109 | * @param array $arr |
||
110 | */ |
||
111 | private function improveSearchQuerying(SearchRequest $request, &$arr) { |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @param SearchRequest $request |
||
120 | * @param array $arr |
||
121 | */ |
||
122 | View Code Duplication | private function improveSearchWildcardQueries(SearchRequest $request, &$arr) { |
|
135 | |||
136 | |||
137 | /** |
||
138 | * @param SearchRequest $request |
||
139 | * @param array $arr |
||
140 | */ |
||
141 | View Code Duplication | private function improveSearchWildcardFilters(SearchRequest $request, &$arr) { |
|
154 | |||
155 | |||
156 | /** |
||
157 | * @param SearchRequest $request |
||
158 | * @param array $arr |
||
159 | */ |
||
160 | private function improveSearchRegexFilters(SearchRequest $request, &$arr) { |
||
173 | |||
174 | |||
175 | /** |
||
176 | * @param SearchRequest $request |
||
177 | * |
||
178 | * @return array<string,array<string,array>> |
||
179 | */ |
||
180 | private function generateSearchQueryContent(SearchRequest $request) { |
||
204 | |||
205 | |||
206 | /** |
||
207 | * @param string $kw |
||
208 | * @param string $word |
||
209 | */ |
||
210 | private function modifySearchQueryContentOnCompleteWord(&$kw, &$word) { |
||
218 | |||
219 | |||
220 | /** |
||
221 | * @param SearchRequest $request |
||
222 | * @param array $kwParts |
||
223 | * |
||
224 | * @return array |
||
225 | */ |
||
226 | private function complementSearchWithParts(SearchRequest $request, $kwParts) { |
||
239 | |||
240 | |||
241 | /** |
||
242 | * @param DocumentAccess $access |
||
243 | * |
||
244 | * @return array<string,array> |
||
245 | */ |
||
246 | private function generateSearchQueryAccess(DocumentAccess $access) { |
||
263 | |||
264 | |||
265 | /** |
||
266 | * @param array $tags |
||
267 | * |
||
268 | * @return array<string,array> |
||
269 | */ |
||
270 | private function generateSearchQueryTags($tags) { |
||
279 | |||
280 | private function generateSearchHighlighting() { |
||
287 | |||
288 | |||
289 | } |
||
290 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.