| Conditions | 20 |
| Paths | 512 |
| Total Lines | 69 |
| Code Lines | 36 |
| Lines | 20 |
| Ratio | 28.99 % |
| 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 |
||
| 122 | public function getResults($pageLength = null, $data = null) |
||
| 123 | { |
||
| 124 | // legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials |
||
| 125 | if (!isset($data) || !is_array($data)) { |
||
| 126 | $data = $_REQUEST; |
||
| 127 | } |
||
| 128 | |||
| 129 | // set language (if present) |
||
| 130 | View Code Duplication | if (class_exists('Translatable')) { |
|
| 131 | if (SiteTree::singleton()->hasExtension('Translatable') && isset($data['searchlocale'])) { |
||
| 132 | if ($data['searchlocale'] == "ALL") { |
||
| 133 | Translatable::disable_locale_filter(); |
||
| 134 | } else { |
||
| 135 | $origLocale = Translatable::get_current_locale(); |
||
| 136 | |||
| 137 | Translatable::set_current_locale($data['searchlocale']); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | $keywords = $data['Search']; |
||
| 143 | |||
| 144 | $andProcessor = create_function('$matches', ' |
||
| 145 | return " +" . $matches[2] . " +" . $matches[4] . " "; |
||
| 146 | '); |
||
| 147 | $notProcessor = create_function('$matches', ' |
||
| 148 | return " -" . $matches[3]; |
||
| 149 | '); |
||
| 150 | |||
| 151 | $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords); |
||
| 152 | $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords); |
||
| 153 | $keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords); |
||
| 154 | $keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords); |
||
| 155 | |||
| 156 | $keywords = $this->addStarsToKeywords($keywords); |
||
| 157 | |||
| 158 | if (!$pageLength) { |
||
| 159 | $pageLength = $this->pageLength; |
||
| 160 | } |
||
| 161 | $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
||
| 162 | |||
| 163 | if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) { |
||
| 164 | $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", true); |
||
| 165 | } else { |
||
| 166 | $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength); |
||
| 167 | } |
||
| 168 | |||
| 169 | // filter by permission |
||
| 170 | if ($results) { |
||
| 171 | foreach ($results as $result) { |
||
| 172 | if (!$result->canView()) { |
||
| 173 | $results->remove($result); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | // reset locale |
||
| 179 | View Code Duplication | if (class_exists('Translatable')) { |
|
| 180 | if (SiteTree::singleton()->hasExtension('Translatable') && isset($data['searchlocale'])) { |
||
| 181 | if ($data['searchlocale'] == "ALL") { |
||
| 182 | Translatable::enable_locale_filter(); |
||
| 183 | } else { |
||
| 184 | Translatable::set_current_locale($origLocale); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | return $results; |
||
| 190 | } |
||
| 191 | |||
| 255 |