| Conditions | 18 |
| Paths | 513 |
| Total Lines | 79 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 71 | public function results($data) |
||
| 72 | { |
||
| 73 | if (isset($data["Search"]) || isset($data["MainSearch"])) { |
||
| 74 | // there is a search |
||
| 75 | Requirements::themedCSS("searchpluspage_searchresults", "searchplus"); |
||
| 76 | if (isset($data["MainSearch"]) || !isset($data["Search"])) { |
||
| 77 | $data["Search"] = $data["MainSearch"]; |
||
| 78 | } |
||
| 79 | //redirect if needed |
||
| 80 | $data["Search"] = urldecode($data["Search"]); |
||
| 81 | $form = $this->SearchPlusForm(); |
||
| 82 | if (!isset($_GET["redirect"])) { |
||
| 83 | self::$search_history_object = SearchHistory::add_entry($data["Search"]); |
||
| 84 | if (self::$search_history_object) { |
||
| 85 | if (self::$search_history_object->RedirectTo && self::$search_history_object->RedirectTo != self::$search_history_object->Title) { |
||
| 86 | $this->redirect( |
||
| 87 | str_replace( |
||
| 88 | "Search=".urlencode(self::$search_history_object->Title), |
||
| 89 | "Search=".urlencode(self::$search_history_object->RedirectTo), |
||
| 90 | HTTP::RAW_setGetVar('redirect', 1, null) |
||
| 91 | ) |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } else { |
||
| 96 | self::$search_history_object = SearchHistory::find_entry($data["Search"]); |
||
| 97 | } |
||
| 98 | //load data for recommended pages |
||
| 99 | $recommendationsSet = $this->Recommendations(); |
||
| 100 | $matchArrayRecommended = array(); |
||
| 101 | $matchArrayResults = array(); |
||
| 102 | if ($recommendationsSet) { |
||
| 103 | foreach ($recommendationsSet as $rec) { |
||
| 104 | $matchArrayRecommended[$rec->ClassName.$rec->ID] = $rec->ClassName.$rec->ID; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | //work out positions |
||
| 108 | $results = $form->getResults(); |
||
| 109 | $query = $form->getSearchQuery(); |
||
| 110 | $startingPosition = isset($_REQUEST["start"]) ? $_REQUEST["start"] : 0; |
||
| 111 | $endingPosition = $startingPosition + Config::inst()->get("SearchPlusPage", "result_length"); |
||
| 112 | $startingPosition++; |
||
| 113 | if ($results) { |
||
| 114 | $total = $results->TotalItems(); |
||
| 115 | } else { |
||
| 116 | $total = 0; |
||
| 117 | } |
||
| 118 | if ($endingPosition > $total) { |
||
| 119 | $endingPosition = $total; |
||
| 120 | } |
||
| 121 | //highlight search text and check which ones are recommended |
||
| 122 | if ($total) { |
||
| 123 | foreach ($results as $result) { |
||
| 124 | $title = $result->getTitle(); |
||
| 125 | $dbField = DBField::create_field($className = "Text", $title); |
||
| 126 | $result->HighlightedTitle = $dbField->ContextSummary(); |
||
| 127 | $result->IsRecommended = false; |
||
| 128 | $matchArrayResults[$result->ClassName.$result->ID] = $result->ClassName.$result->ID; |
||
| 129 | if (isset($matchArrayRecommended[$result->ClassName.$result->ID])) { |
||
| 130 | $result->IsRecommended = true; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | $data = array( |
||
| 135 | 'Results' => $results, |
||
| 136 | 'Query' => $query, |
||
| 137 | 'From' => $startingPosition, |
||
| 138 | 'To' => $endingPosition, |
||
| 139 | 'Total' => $total, |
||
| 140 | 'HasResults' => $total ? true : false, |
||
| 141 | 'Recommendations' => $this->Recommendations(), |
||
| 142 | 'RecommendedSearchPlusSection' => $this->dataRecord->RecommendedSearchPlusSections(), |
||
| 143 | ); |
||
| 144 | $this->Title = 'Search Results'; |
||
| 145 | $this->MenuTitle = 'Search Results'; |
||
| 146 | return $this->customise($data)->renderWith(array('SearchPlusPage_results', 'Page')); |
||
| 147 | } |
||
| 148 | return array(); |
||
| 149 | } |
||
| 150 | |||
| 253 |