Conditions | 16 |
Paths | 256 |
Total Lines | 69 |
Code Lines | 39 |
Lines | 18 |
Ratio | 26.09 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 |
||
128 | public function getResults() |
||
129 | { |
||
130 | // Get request data from request handler |
||
131 | $request = $this->getRequestHandler()->getRequest(); |
||
132 | |||
133 | // set language (if present) |
||
134 | $locale = null; |
||
135 | $origLocale = null; |
||
136 | if (class_exists('Translatable')) { |
||
137 | $locale = $request->requestVar('searchlocale'); |
||
138 | View Code Duplication | if (SiteTree::singleton()->hasExtension('Translatable') && $locale) { |
|
139 | if ($locale === "ALL") { |
||
140 | Translatable::disable_locale_filter(); |
||
141 | } else { |
||
142 | $origLocale = Translatable::get_current_locale(); |
||
143 | |||
144 | Translatable::set_current_locale($locale); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | |||
149 | $keywords = $request->requestVar('Search'); |
||
150 | |||
151 | $andProcessor = create_function('$matches', ' |
||
152 | return " +" . $matches[2] . " +" . $matches[4] . " "; |
||
153 | '); |
||
154 | $notProcessor = create_function('$matches', ' |
||
155 | return " -" . $matches[3]; |
||
156 | '); |
||
157 | |||
158 | $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords); |
||
159 | $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords); |
||
160 | $keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords); |
||
161 | $keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords); |
||
162 | |||
163 | $keywords = $this->addStarsToKeywords($keywords); |
||
164 | |||
165 | $pageLength = $this->getPageLength(); |
||
166 | $start = $request->requestVar('start') ?: 0; |
||
167 | |||
168 | $booleanSearch = |
||
169 | strpos($keywords, '"') !== false || |
||
170 | strpos($keywords, '+') !== false || |
||
171 | strpos($keywords, '-') !== false || |
||
172 | strpos($keywords, '*') !== false; |
||
173 | $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", $booleanSearch); |
||
174 | |||
175 | // filter by permission |
||
176 | if ($results) { |
||
177 | foreach ($results as $result) { |
||
178 | if (!$result->canView()) { |
||
179 | $results->remove($result); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | // reset locale |
||
185 | View Code Duplication | if (class_exists('Translatable')) { |
|
186 | if (SiteTree::singleton()->hasExtension('Translatable') && $locale) { |
||
187 | if ($locale == "ALL") { |
||
188 | Translatable::enable_locale_filter(); |
||
189 | } else { |
||
190 | Translatable::set_current_locale($origLocale); |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | |||
195 | return $results; |
||
196 | } |
||
197 | |||
250 |