Conditions | 2 |
Paths | 2 |
Total Lines | 147 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Tests | 52 |
CRAP Score | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
130 | 1 | public function generateConfig() { |
|
131 | 1 | $settings = array(); |
|
132 | 1 | $settings['analysis'] = array(); |
|
133 | |||
134 | // create redefined filters in this array, e.g. tweaked stopwords |
||
135 | |||
136 | 1 | $properties = array(); |
|
137 | 1 | $analyzerNotStemmed = array(); |
|
138 | 1 | $analyzerFolded = array(); |
|
139 | |||
140 | 1 | $analyzerNotStemmed['type'] = 'custom'; |
|
141 | |||
142 | 1 | $this->addFilter('no_single_chars', array( |
|
143 | 1 | 'type' => 'length', |
|
144 | 'min' => 2 |
||
145 | 1 | )); |
|
146 | |||
147 | |||
148 | /* |
||
149 | if (sizeof($this->stopWords) > 0) { |
||
150 | $stopwordFilter = array(); |
||
151 | $stopwordFilter['type'] = 'stop'; |
||
152 | $stopwordFilter['stopwords'] = $this->stopWords; |
||
153 | $this->filters['stopword_filter'] = $stopwordFilter; |
||
154 | } |
||
155 | */ |
||
156 | |||
157 | //$analyzerStemmed['char_filter'] = array('html_strip'); |
||
158 | 1 | $filterNames = array_keys($this->filters); |
|
159 | |||
160 | //$analyzerNotStemmed['char_filter'] = array('html_strip'); |
||
161 | 1 | $analyzerNotStemmed['tokenizer'] = 'uax_url_email'; |
|
162 | 1 | array_push($filterNames, 'lowercase'); |
|
163 | 1 | $analyzerNotStemmed['filter'] = array('no_single_chars', 'lowercase', $this->stopWordFilter); |
|
164 | |||
165 | //Autocomplete filter |
||
166 | /* |
||
167 | "autocomplete": { |
||
168 | "type": "custom", |
||
169 | "tokenizer": "standard", |
||
170 | "filter": [ |
||
171 | "lowercase", |
||
172 | "autocomplete_filter" |
||
173 | ] |
||
174 | } |
||
175 | */ |
||
176 | 1 | $this->addFilter('autocomplete', array( |
|
177 | 1 | 'type' => 'nGram', |
|
178 | 1 | 'min_gram' => 2, |
|
179 | 1 | 'max_gram' => 20, |
|
180 | 1 | 'token_chars' => array('letter', 'digit','punctuation', 'symbol') |
|
181 | 1 | )); |
|
182 | |||
183 | 1 | $this->addAnalyzer('autocomplete_index_analyzer',array( |
|
184 | 1 | 'type' => 'custom', |
|
185 | 1 | 'tokenizer' => 'whitespace', |
|
186 | 'filter' => array( |
||
187 | 1 | 'lowercase', |
|
188 | 1 | 'asciifolding', |
|
189 | 'autocomplete' |
||
190 | 1 | ) |
|
191 | 1 | )); |
|
192 | |||
193 | 1 | $this->addAnalyzer('autocomplete_search_analyzer',array( |
|
194 | 1 | 'type' => 'custom', |
|
195 | 1 | 'tokenizer' => 'whitespace', |
|
196 | 'filter' => array( |
||
197 | 1 | 'lowercase', |
|
198 | 'asciifolding' |
||
199 | 1 | ) |
|
200 | 1 | )); |
|
201 | |||
202 | //Folded analyzer |
||
203 | 1 | $analyzerFolded['tokenizer'] = 'uax_url_email'; |
|
204 | 1 | $analyzerFolded['filters'] = array('lowercase', 'asciifolding'); |
|
205 | |||
206 | |||
207 | |||
208 | //HTML needs to have been removed for all indexes |
||
209 | //stemmed is set by the specific language provider |
||
210 | 1 | $this->analyzers['unstemmed'] = $analyzerNotStemmed; |
|
211 | |||
212 | |||
213 | 1 | if ($this->foldedAscii) { |
|
214 | 1 | $analyzers['folded'] = $analyzerFolded; |
|
215 | 1 | } |
|
216 | |||
217 | //Store bigrams in the index, namely pairs of words |
||
218 | 1 | $this->addFilter('filter_shingle', array( |
|
219 | 1 | 'type' => 'shingle', |
|
220 | 1 | 'min_shingle_size' => 2, |
|
221 | 1 | 'max_shingle_size' => 2, |
|
222 | 'output_unigrams' => false |
||
223 | 1 | )); |
|
224 | |||
225 | //See https://www.elastic.co/blog/searching-with-shingles?q=shingle for details |
||
226 | 1 | $this->addAnalyzer('shingles', array( |
|
227 | // Ensure URLs happily tokenized |
||
228 | 1 | 'tokenizer' => 'uax_url_email', |
|
229 | 1 | 'filter' => array("lowercase", "filter_shingle"), |
|
230 | 'type' => 'custom' |
||
231 | 1 | )); |
|
232 | |||
233 | 1 | $settings['analysis']['analyzer'] = $this->analyzers; |
|
234 | 1 | $settings['analysis']['filter'] = $this->filters; |
|
235 | |||
236 | |||
237 | 1 | $properties['index'] = $settings; |
|
238 | |||
239 | /* |
||
240 | |||
241 | if ($this->foldedAscii) { |
||
242 | $foldingFilter = array('my_ascii_folding' => array( |
||
243 | "type" => "asciifolding", |
||
244 | "preserve_original" => 'true' |
||
245 | )); |
||
246 | array_push($filters, $foldingFilter); |
||
247 | } |
||
248 | */ |
||
249 | |||
250 | |||
251 | /* |
||
252 | $json = '{ |
||
253 | "settings": { |
||
254 | "analysis": { |
||
255 | "analyzer": { |
||
256 | "stemmed": { |
||
257 | "type": "english", |
||
258 | "stem_exclusion": [ "organization", "organizations" ], |
||
259 | "stopwords": [ |
||
260 | "a", "an", "and", "are", "as", "at", "be", "but", "by", "for", |
||
261 | "if", "in", "into", "is", "it", "of", "on", "or", "such", "that", |
||
262 | "the", "their", "then", "there", "these", "they", "this", "to", |
||
263 | "was", "will", "with" |
||
264 | ] |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | }'; |
||
270 | */ |
||
271 | //$this->extend('alterIndexingProperties', $properties); |
||
272 | // |
||
273 | // |
||
274 | |||
275 | 1 | return $properties; |
|
276 | } |
||
277 | } |
||
278 |
This check marks private properties in classes that are never used. Those properties can be removed.