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 |
||
8 | class Highlight extends SolrRequest implements ComponentInterface |
||
9 | { |
||
10 | const FORMATTER_SIMPLE = 'formatter'; |
||
11 | |||
12 | /** |
||
13 | * {@inheritDoc} |
||
14 | * |
||
15 | * Sets the query that is used in the base query. |
||
16 | */ |
||
17 | public function preMergeParams(SolrRequest $request) |
||
23 | |||
24 | /** |
||
25 | * {@inheritDoc} |
||
26 | * |
||
27 | * Enables highlighting. |
||
28 | */ |
||
29 | public function init() |
||
33 | |||
34 | /** |
||
35 | * @param bool $highlight |
||
36 | * |
||
37 | * @return \Psolr\Component\Highlight |
||
38 | * |
||
39 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl |
||
40 | */ |
||
41 | public function highlight($highlight = true) |
||
45 | |||
46 | /** |
||
47 | * @param string $query |
||
48 | * |
||
49 | * @return \Psolr\Component\Highlight |
||
50 | * |
||
51 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.q |
||
52 | */ |
||
53 | public function setQuery($query) |
||
57 | |||
58 | /** |
||
59 | * @param int $snippets |
||
60 | * |
||
61 | * @return \Psolr\Component\Highlight |
||
62 | * |
||
63 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.snippets |
||
64 | */ |
||
65 | public function setSnippets($snippets) |
||
69 | |||
70 | /** |
||
71 | * @param int $fragsize |
||
72 | * |
||
73 | * @return \Psolr\Component\Highlight |
||
74 | * |
||
75 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragsize |
||
76 | */ |
||
77 | public function setFragsize($fragsize) |
||
81 | |||
82 | /** |
||
83 | * @param bool $merge |
||
84 | * |
||
85 | * @return \Psolr\Component\Highlight |
||
86 | * |
||
87 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.mergeContiguous |
||
88 | */ |
||
89 | public function mergeContiguous($merge = true) |
||
93 | |||
94 | /** |
||
95 | * @param bool $require |
||
96 | * |
||
97 | * @return \Psolr\Component\Highlight |
||
98 | * |
||
99 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.requireFieldMatch |
||
100 | */ |
||
101 | public function requireFieldMatch($require = true) |
||
105 | |||
106 | /** |
||
107 | * @param int $chars |
||
108 | * |
||
109 | * @return \Psolr\Component\Highlight |
||
110 | * |
||
111 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxAnalyzedChars |
||
112 | */ |
||
113 | public function setMaxAnalyzedChars($chars) |
||
117 | |||
118 | /** |
||
119 | * @param string $field |
||
120 | * |
||
121 | * @return \Psolr\Component\Highlight |
||
122 | * |
||
123 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.alternateField |
||
124 | */ |
||
125 | public function setAlternateField($field) |
||
129 | |||
130 | /** |
||
131 | * @param int $length |
||
132 | * |
||
133 | * @return \Psolr\Component\Highlight |
||
134 | * |
||
135 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxAlternateFieldLength |
||
136 | */ |
||
137 | public function setMaxAlternateFieldLength($length) |
||
141 | |||
142 | /** |
||
143 | * @param bool $preserve |
||
144 | * |
||
145 | * @return \Psolr\Component\Highlight |
||
146 | * |
||
147 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.preserveMulti |
||
148 | */ |
||
149 | public function preserveMulti($preserve = true) |
||
153 | |||
154 | /** |
||
155 | * @param int $max |
||
156 | * |
||
157 | * @return \Psolr\Component\Highlight |
||
158 | * |
||
159 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxMultiValuedToExamine |
||
160 | */ |
||
161 | public function setMaxMultiValuedToExamine($max) |
||
165 | |||
166 | /** |
||
167 | * @param int $max |
||
168 | * |
||
169 | * @return \Psolr\Component\Highlight |
||
170 | * |
||
171 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.maxMultiValuedToMatch |
||
172 | */ |
||
173 | public function setMaxMultiValuedToMatch($max) |
||
177 | |||
178 | /** |
||
179 | * @param string $formatter |
||
180 | * |
||
181 | * @return \Psolr\Component\Highlight |
||
182 | * |
||
183 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.formatter |
||
184 | */ |
||
185 | public function setFormatter($formatter) |
||
189 | |||
190 | /** |
||
191 | * @param string $text |
||
192 | * |
||
193 | * @return \Psolr\Component\Highlight |
||
194 | * |
||
195 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.simple.pre.2Fhl.simple.post |
||
196 | */ |
||
197 | public function setSimplePre($text) |
||
201 | |||
202 | /** |
||
203 | * @param string $text |
||
204 | * |
||
205 | * @return \Psolr\Component\Highlight |
||
206 | * |
||
207 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.simple.pre.2Fhl.simple.post |
||
208 | */ |
||
209 | public function setSimplePost($text) |
||
213 | |||
214 | /** |
||
215 | * Sets the html element used for highlighting, e.g. "em" |
||
216 | * |
||
217 | * @param string $element |
||
218 | * |
||
219 | * @return \Psolr\Component\Highlight |
||
220 | * |
||
221 | * @see \Psolr\Component\Highlight::setFormatter() |
||
222 | * @see \Psolr\Component\Highlight::setSimplePre() |
||
223 | * @see \Psolr\Component\Highlight::setSimplePost() |
||
224 | */ |
||
225 | public function setHighlighterElement($element) |
||
233 | |||
234 | /** |
||
235 | * @param string $fragmenter |
||
236 | * |
||
237 | * @return \Psolr\Component\Highlight |
||
238 | * |
||
239 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragmenter |
||
240 | */ |
||
241 | public function setFragmenter($fragmenter) |
||
245 | |||
246 | /** |
||
247 | * @param string $builder |
||
248 | * |
||
249 | * @return \Psolr\Component\Highlight |
||
250 | * |
||
251 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragListBuilder |
||
252 | */ |
||
253 | public function setFragListBuilder($builder) |
||
257 | |||
258 | /** |
||
259 | * @param string $scanner |
||
260 | * |
||
261 | * @return \Psolr\Component\Highlight |
||
262 | * |
||
263 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.boundaryScanner |
||
264 | */ |
||
265 | public function setBoundaryScanner($scanner) |
||
269 | |||
270 | /** |
||
271 | * @param string $builder |
||
272 | * |
||
273 | * @return \Psolr\Component\Highlight |
||
274 | * |
||
275 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.fragmentsBuilder |
||
276 | */ |
||
277 | public function setFragmentsBuilder($builder) |
||
281 | |||
282 | /** |
||
283 | * @param int $maxScan |
||
284 | * |
||
285 | * @return \Psolr\Component\Highlight |
||
286 | * |
||
287 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.maxScan |
||
288 | */ |
||
289 | public function setBoundaryScannerMaxScan($maxScan) |
||
293 | |||
294 | /** |
||
295 | * @param string $chars |
||
296 | * |
||
297 | * @return \Psolr\Component\Highlight |
||
298 | * |
||
299 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.chars |
||
300 | */ |
||
301 | public function setBoundaryScannerChars($chars) |
||
305 | |||
306 | /** |
||
307 | * @param string $type |
||
308 | * |
||
309 | * @return \Psolr\Component\Highlight |
||
310 | * |
||
311 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.type |
||
312 | */ |
||
313 | public function setBoundaryScannerType($type) |
||
317 | |||
318 | /** |
||
319 | * @param string $language |
||
320 | * |
||
321 | * @return \Psolr\Component\Highlight |
||
322 | * |
||
323 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.language |
||
324 | */ |
||
325 | public function setBoundaryScannerLanguage($language) |
||
329 | |||
330 | /** |
||
331 | * @param string $country |
||
332 | * |
||
333 | * @return \Psolr\Component\Highlight |
||
334 | * |
||
335 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.bs.country |
||
336 | */ |
||
337 | public function setBoundaryScannerCountry($country) |
||
341 | |||
342 | /** |
||
343 | * @param bool $use |
||
344 | * |
||
345 | * @return \Psolr\Component\Highlight |
||
346 | * |
||
347 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.useFastVectorHighlighter |
||
348 | */ |
||
349 | public function useFastVectorHighlighter($use = true) |
||
353 | |||
354 | /** |
||
355 | * @param bool $use |
||
356 | * |
||
357 | * @return \Psolr\Component\Highlight |
||
358 | * |
||
359 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.usePhraseHighlighter |
||
360 | */ |
||
361 | public function usePhraseHighlighter($use = true) |
||
365 | |||
366 | /** |
||
367 | * @param bool $multiTerm |
||
368 | * |
||
369 | * @return \Psolr\Component\Highlight |
||
370 | * |
||
371 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.highlightMultiTerm |
||
372 | */ |
||
373 | public function highlightMultiTerm($multiTerm = true) |
||
377 | |||
378 | /** |
||
379 | * @param float $slop |
||
380 | * |
||
381 | * @return \Psolr\Component\Highlight |
||
382 | * |
||
383 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.slop |
||
384 | */ |
||
385 | public function setRegexSlop($slop) |
||
389 | |||
390 | /** |
||
391 | * @param string $pattern |
||
392 | * |
||
393 | * @return \Psolr\Component\Highlight |
||
394 | * |
||
395 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.pattern |
||
396 | */ |
||
397 | public function setRegexPattern($pattern) |
||
401 | |||
402 | /** |
||
403 | * @param int $max |
||
404 | * |
||
405 | * @return \Psolr\Component\Highlight |
||
406 | * |
||
407 | * @see http://wiki.apache.org/solr/HighlightingParameters#hl.regex.maxAnalyzedChars |
||
408 | */ |
||
409 | public function setRegexMaxAnalyzedChars($max) |
||
413 | } |
||
414 |
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.