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( |
||
107 | |||
108 | |||
109 | /** |
||
110 | * @param SearchRequest $request |
||
111 | * @param array $arr |
||
112 | */ |
||
113 | private function improveSearchQuerying(SearchRequest $request, &$arr) { |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @param SearchRequest $request |
||
121 | * @param array $arr |
||
122 | */ |
||
123 | View Code Duplication | private function improveSearchWildcardQueries(SearchRequest $request, &$arr) { |
|
136 | |||
137 | |||
138 | /** |
||
139 | * @param SearchRequest $request |
||
140 | * @param array $arr |
||
141 | */ |
||
142 | View Code Duplication | private function improveSearchWildcardFilters(SearchRequest $request, &$arr) { |
|
155 | |||
156 | |||
157 | /** |
||
158 | * @param string $string |
||
159 | * |
||
160 | * @return array<string,array<string,array>> |
||
161 | */ |
||
162 | private function generateSearchQueryContent($string) { |
||
179 | |||
180 | |||
181 | /** |
||
182 | * @param string $kw |
||
183 | * @param string $word |
||
184 | */ |
||
185 | private function modifySearchQueryContentOnCompleteWord(&$kw, &$word) { |
||
193 | |||
194 | |||
195 | /** |
||
196 | * @param DocumentAccess $access |
||
197 | * |
||
198 | * @return array<string,array> |
||
199 | */ |
||
200 | private function generateSearchQueryAccess(DocumentAccess $access) { |
||
217 | |||
218 | |||
219 | /** |
||
220 | * @param array $tags |
||
221 | * |
||
222 | * @return array<string,array> |
||
223 | */ |
||
224 | private function generateSearchQueryTags($tags) { |
||
233 | |||
234 | private function generateSearchHighlighting() { |
||
241 | |||
242 | |||
243 | } |
||
244 |
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.