| Conditions | 17 |
| Paths | 128 |
| Total Lines | 68 |
| Code Lines | 37 |
| Lines | 18 |
| Ratio | 26.47 % |
| Changes | 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 |
||
| 129 | public function getResults() |
||
| 130 | { |
||
| 131 | // Get request data from request handler |
||
| 132 | $request = $this->getRequestHandler()->getRequest(); |
||
| 133 | |||
| 134 | // set language (if present) |
||
| 135 | $locale = null; |
||
| 136 | $origLocale = null; |
||
| 137 | if (class_exists('Translatable')) { |
||
| 138 | $locale = $request->requestVar('searchlocale'); |
||
| 139 | View Code Duplication | if (SiteTree::singleton()->hasExtension('Translatable') && $locale) { |
|
| 140 | if ($locale === "ALL") { |
||
| 141 | Translatable::disable_locale_filter(); |
||
| 142 | } else { |
||
| 143 | $origLocale = Translatable::get_current_locale(); |
||
| 144 | |||
| 145 | Translatable::set_current_locale($locale); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | $keywords = $request->requestVar('Search'); |
||
| 151 | |||
| 152 | $andProcessor = create_function('$matches', ' |
||
| 153 | return " +" . $matches[2] . " +" . $matches[4] . " "; |
||
| 154 | '); |
||
| 155 | $notProcessor = create_function('$matches', ' |
||
| 156 | return " -" . $matches[3]; |
||
| 157 | '); |
||
| 158 | |||
| 159 | $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords); |
||
| 160 | $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords); |
||
| 161 | $keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords); |
||
| 162 | $keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords); |
||
| 163 | |||
| 164 | $keywords = $this->addStarsToKeywords($keywords); |
||
| 165 | |||
| 166 | $pageLength = $this->getPageLength(); |
||
| 167 | $start = $request->requestVar('start') ?: 0; |
||
| 168 | |||
| 169 | if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) { |
||
| 170 | $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", true); |
||
| 171 | } else { |
||
| 172 | $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength); |
||
| 173 | } |
||
| 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 |