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 |
||
| 38 | class SearchMappingService { |
||
| 39 | |||
| 40 | /** @var ConfigService */ |
||
| 41 | private $configService; |
||
| 42 | |||
| 43 | /** @var MiscService */ |
||
| 44 | private $miscService; |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * MappingService constructor. |
||
| 49 | * |
||
| 50 | * @param ConfigService $configService |
||
| 51 | * @param MiscService $miscService |
||
| 52 | */ |
||
| 53 | public function __construct(ConfigService $configService, MiscService $miscService) { |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * @param IFullTextSearchProvider $provider |
||
| 61 | * @param DocumentAccess $access |
||
| 62 | * @param SearchRequest $request |
||
| 63 | * |
||
| 64 | * @return array |
||
|
|
|||
| 65 | * @throws ConfigurationException |
||
| 66 | * @throws SearchQueryGenerationException |
||
| 67 | */ |
||
| 68 | public function generateSearchQuery( |
||
| 75 | |||
| 76 | |||
| 77 | /** |
||
| 78 | * @param IFullTextSearchProvider $provider |
||
| 79 | * @param DocumentAccess $access |
||
| 80 | * @param SearchRequest $request |
||
| 81 | * |
||
| 82 | * @return array |
||
| 83 | * @throws ConfigurationException |
||
| 84 | * @throws SearchQueryGenerationException |
||
| 85 | */ |
||
| 86 | public function generateSearchQueryParams( |
||
| 110 | |||
| 111 | |||
| 112 | /** |
||
| 113 | * @param SearchRequest $request |
||
| 114 | * @param array $arr |
||
| 115 | */ |
||
| 116 | private function improveSearchQuerying(SearchRequest $request, &$arr) { |
||
| 121 | |||
| 122 | |||
| 123 | /** |
||
| 124 | * @param SearchRequest $request |
||
| 125 | * @param array $arr |
||
| 126 | */ |
||
| 127 | View Code Duplication | private function improveSearchWildcardQueries(SearchRequest $request, &$arr) { |
|
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * @param SearchRequest $request |
||
| 144 | * @param array $arr |
||
| 145 | */ |
||
| 146 | View Code Duplication | private function improveSearchWildcardFilters(SearchRequest $request, &$arr) { |
|
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * @param SearchRequest $request |
||
| 163 | * @param array $arr |
||
| 164 | */ |
||
| 165 | private function improveSearchRegexFilters(SearchRequest $request, &$arr) { |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * @param SearchRequest $request |
||
| 182 | * |
||
| 183 | * @return array<string,array<string,array>> |
||
| 184 | * @throws SearchQueryGenerationException |
||
| 185 | */ |
||
| 186 | private function generateSearchQueryContent(SearchRequest $request) { |
||
| 205 | |||
| 206 | |||
| 207 | /** |
||
| 208 | * @param string $word |
||
| 209 | * |
||
| 210 | * @return QueryContent |
||
| 211 | * @throws QueryContentGenerationException |
||
| 212 | */ |
||
| 213 | private function generateQueryContent($word) { |
||
| 222 | |||
| 223 | |||
| 224 | /** |
||
| 225 | * @param SearchRequest $request |
||
| 226 | * @param QueryContent[] $queryContents |
||
| 227 | * |
||
| 228 | * @return array |
||
| 229 | */ |
||
| 230 | private function generateSearchQueryFromQueryContent(SearchRequest $request, $queryContents) { |
||
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * @param QueryContent $queryContent |
||
| 256 | * @param array $fields |
||
| 257 | * |
||
| 258 | * @return array |
||
| 259 | */ |
||
| 260 | private function generateQueryContentFields(QueryContent $queryContent, $fields) { |
||
| 269 | |||
| 270 | |||
| 271 | /** |
||
| 272 | * @param DocumentAccess $access |
||
| 273 | * |
||
| 274 | * @return array<string,array> |
||
| 275 | */ |
||
| 276 | private function generateSearchQueryAccess(DocumentAccess $access) { |
||
| 293 | |||
| 294 | |||
| 295 | /** |
||
| 296 | * @param array $tags |
||
| 297 | * |
||
| 298 | * @return array<string,array> |
||
| 299 | */ |
||
| 300 | private function generateSearchQueryTags($tags) { |
||
| 309 | |||
| 310 | private function generateSearchHighlighting() { |
||
| 317 | |||
| 318 | |||
| 319 | } |
||
| 320 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.