Conditions | 4 |
Paths | 2 |
Total Lines | 102 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 16 | ||
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 declare(strict_types = 1); |
||
61 | public function index(): \SilverStripe\View\ViewableData_Customised |
||
62 | { |
||
63 | // @todo search indexes addition |
||
64 | $q = $this->getRequest()->getVar('q'); |
||
65 | |||
66 | /** @var array $selected */ |
||
67 | $selected = $this->getRequest()->getVars(); |
||
68 | |||
69 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $model */ |
||
70 | $model = SearchPage::get_by_id(SearchPage::class, $this->ID); |
||
71 | |||
72 | // @todo why? |
||
73 | // unset($selected['start']); |
||
74 | |||
75 | $results = new SearchResults(); |
||
76 | |||
77 | |||
78 | //unset($selected['q']); |
||
79 | |||
80 | if (isset($q) || $model->ShowAllIfEmptyQuery || isset($selected['q'])) { |
||
81 | $results = $this->performSearchIncludingFacets($selected, $model, $q); |
||
82 | } |
||
83 | |||
84 | |||
85 | /* |
||
86 | * |
||
87 | * // get suggestions |
||
88 | |||
89 | $factory = new SuggesterFactory(); |
||
90 | |||
91 | $suggester = $factory->getSuggester(); |
||
92 | |||
93 | // @todo this is returning blank |
||
94 | $suggester->setIndex($model->IndexToSearch); |
||
95 | $suggestions = $suggester->suggest($q); |
||
96 | |||
97 | |||
98 | |||
99 | |||
100 | $facetted = isset($results['AllFacets']); |
||
101 | |||
102 | |||
103 | |||
104 | $targetFacet = new ArrayList(); |
||
105 | if (isset($model->ShowTagCloudFor)) { |
||
106 | // get the tag cloud from calculated facets, but if not calculated, ie the arrive on the page case, |
||
107 | // calculate them |
||
108 | if ($facetted) { |
||
109 | $facets = $results['AllFacets']; |
||
110 | } else { |
||
111 | $proxyResults = $this->performSearchIncludingFacets($selected, $model, $q); |
||
112 | $facets = $proxyResults['AllFacets']; |
||
113 | } |
||
114 | |||
115 | foreach ($facets as $facet) { |
||
116 | $name = $facet->getField('Name'); |
||
117 | if ($name === $model->ShowTagCloudFor) { |
||
118 | $targetFacet = $facet->getField('Facets'); |
||
119 | |||
120 | break; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | $facetArray = $targetFacet->toArray(); |
||
125 | $minSize = 10; |
||
126 | $maxSize = 40; |
||
127 | $maxCount = 0; |
||
128 | foreach ($facetArray as $tag) { |
||
129 | $count = $tag['Count']; |
||
130 | $maxCount = $count > $maxCount |
||
131 | ? $count |
||
132 | : $maxCount; |
||
133 | } |
||
134 | |||
135 | $tagCloud = new ArrayList(); |
||
136 | foreach ($facetArray as $tag) { |
||
137 | $size = $minSize + ($maxSize - $minSize) * $tag['Count'] / $maxCount; |
||
138 | $size = \round($size); |
||
139 | $row = new ArrayData([ |
||
140 | 'Name' => $tag['Value'], |
||
141 | 'Size' => $size, |
||
142 | 'Params' => $tag['Params'], |
||
143 | ]); |
||
144 | $tagCloud->push($row); |
||
145 | } |
||
146 | |||
147 | $results['TagCloud'] = $tagCloud; |
||
148 | } |
||
149 | |||
150 | |||
151 | //for($i = 3; $i < 40; $i++) { |
||
152 | // echo "li.tag{$i} { font-size: {$i}px;};\n"; |
||
153 | //} |
||
154 | |||
155 | */ |
||
156 | |||
157 | |||
158 | // defer showing to the template level, still get facets, as this allows optionally for likes of a tag cloud |
||
159 | // $results['ShowAllIfEmptyQuery'] = $model->ShowAllIfEmptyQuery; |
||
160 | // $results['CleanedLink'] = $this->Link(); |
||
161 | |||
162 | return $this->renderSearchResults($model, $results); |
||
163 | } |
||
293 |