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 |
||
10 | class Spellcheck extends SolrRequest implements ComponentInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $handlerName = 'spell'; |
||
16 | |||
17 | /** |
||
18 | * $var string |
||
19 | */ |
||
20 | protected $responseClass = '\PSolr\Response\Spellcheck'; |
||
21 | |||
22 | /** |
||
23 | * {@inheritDoc} |
||
24 | * |
||
25 | * Sets the query that is used in the base query. |
||
26 | */ |
||
27 | public function preMergeParams(SolrRequest $request) |
||
33 | |||
34 | /** |
||
35 | * {@inheritDoc} |
||
36 | * |
||
37 | * Enables spell checking. |
||
38 | */ |
||
39 | public function init() |
||
43 | |||
44 | /** |
||
45 | * @param string $query |
||
46 | * |
||
47 | * @return \PSolr\Request\Suggest |
||
48 | * |
||
49 | * @see http://wiki.apache.org/solr/SpellCheckComponent#q_OR_spellcheck.q |
||
50 | */ |
||
51 | public function setQuery($query) |
||
55 | |||
56 | /** |
||
57 | * @param bool $spellcheck |
||
58 | * |
||
59 | * @return \Psolr\Component\Spellcheck |
||
60 | * |
||
61 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck |
||
62 | */ |
||
63 | public function spellcheck($spellcheck = true) |
||
67 | |||
68 | /** |
||
69 | * @param bool $build |
||
70 | * |
||
71 | * @return \Psolr\Component\Spellcheck |
||
72 | * |
||
73 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.build |
||
74 | */ |
||
75 | public function build($build = true) |
||
79 | |||
80 | /** |
||
81 | * @param bool $reload |
||
82 | * |
||
83 | * @return \Psolr\Component\Spellcheck |
||
84 | * |
||
85 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.reload |
||
86 | */ |
||
87 | public function reload($reload = true) |
||
91 | |||
92 | /** |
||
93 | * @param string $dictionary |
||
94 | * |
||
95 | * @return \Psolr\Component\Spellcheck |
||
96 | * |
||
97 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.dictionary |
||
98 | */ |
||
99 | public function setDictionary($dictionary) |
||
103 | |||
104 | /** |
||
105 | * @param int $count |
||
106 | * |
||
107 | * @return \Psolr\Component\Spellcheck |
||
108 | * |
||
109 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.count |
||
110 | */ |
||
111 | public function setCount($count) |
||
115 | |||
116 | /** |
||
117 | * @param int $count |
||
118 | * |
||
119 | * @return \Psolr\Component\Spellcheck |
||
120 | * |
||
121 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.alternativeTermCount |
||
122 | */ |
||
123 | public function setAlternativeTermCount($count) |
||
127 | |||
128 | /** |
||
129 | * @param bool $onlyMorePopular |
||
130 | * |
||
131 | * @return \Psolr\Component\Spellcheck |
||
132 | * |
||
133 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.onlyMorePopular |
||
134 | */ |
||
135 | public function onlyMorePopular($onlyMorePopular = true) |
||
139 | |||
140 | /** |
||
141 | * @param int $maxResults |
||
142 | * |
||
143 | * @return \Psolr\Component\Spellcheck |
||
144 | * |
||
145 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxResultsForSuggest |
||
146 | */ |
||
147 | public function setMaxResultsForSuggest($maxResults) |
||
151 | |||
152 | /** |
||
153 | * @param bool $collate |
||
154 | * |
||
155 | * @return \Psolr\Component\Spellcheck |
||
156 | * |
||
157 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collate |
||
158 | */ |
||
159 | public function collate($collate = true) |
||
163 | |||
164 | /** |
||
165 | * @param int $maxCollations |
||
166 | * |
||
167 | * @return \Psolr\Component\Spellcheck |
||
168 | * |
||
169 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxCollations |
||
170 | */ |
||
171 | public function setMaxCollations($maxCollations) |
||
175 | |||
176 | /** |
||
177 | * @param int $maxTries |
||
178 | * |
||
179 | * @return \Psolr\Component\Spellcheck |
||
180 | * |
||
181 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxCollationTries |
||
182 | */ |
||
183 | public function setMaxCollationTries($maxTries) |
||
187 | |||
188 | /** |
||
189 | * @param string $param |
||
190 | * @param string $value |
||
191 | * |
||
192 | * @return \Psolr\Component\Spellcheck |
||
193 | * |
||
194 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateParam.XX |
||
195 | */ |
||
196 | public function setCollateParam($param, $value) |
||
200 | |||
201 | /** |
||
202 | * @param bool $collate |
||
203 | * |
||
204 | * @return \Psolr\Component\Spellcheck |
||
205 | * |
||
206 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateExtendedResults |
||
207 | */ |
||
208 | public function collateExtendedResults($collate = true) |
||
212 | |||
213 | /** |
||
214 | * @param int $maxDocs |
||
215 | * |
||
216 | * @return \Psolr\Component\Spellcheck |
||
217 | * |
||
218 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateMaxCollectDocs |
||
219 | */ |
||
220 | public function setCollateMaxCollectDocs($maxDocs) |
||
224 | |||
225 | /** |
||
226 | * @param float $accuracy |
||
227 | * |
||
228 | * @return \Psolr\Component\Spellcheck |
||
229 | * |
||
230 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.accuracy |
||
231 | */ |
||
232 | public function setAccuracy($accuracy) |
||
236 | |||
237 | /** |
||
238 | * @param string $dictionary |
||
239 | * @param string $key |
||
240 | * @param string $value |
||
241 | * |
||
242 | * @return \Psolr\Component\Spellcheck |
||
243 | * |
||
244 | * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck..3CDICT_NAME.3E.key |
||
245 | */ |
||
246 | public function setDictionaryParam($dictionary, $key, $value) |
||
250 | } |
||
251 |
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.