| Conditions | 7 |
| Paths | 8 |
| Total Lines | 134 |
| Code Lines | 33 |
| 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); |
||
| 41 | public function index(): \SilverStripe\View\ViewableData_Customised |
||
| 42 | { |
||
| 43 | // @todo search indexes addition |
||
| 44 | $q = $this->getRequest()->getVar('q'); |
||
| 45 | |||
| 46 | /** @var array $selected */ |
||
| 47 | $selected = $this->getRequest()->getVars(); |
||
| 48 | |||
| 49 | /** @var \Suilven\FreeTextSearch\Page\SearchPage $model */ |
||
| 50 | $model = SearchPage::get_by_id(SearchPage::class, $this->ID); |
||
| 51 | |||
| 52 | |||
| 53 | unset($selected['start']); |
||
| 54 | |||
| 55 | $results = new SearchResults(); |
||
| 56 | |||
| 57 | |||
| 58 | //unset($selected['q']); |
||
| 59 | |||
| 60 | if (isset($q) || $model->ShowAllIfEmptyQuery || isset($selected)) { |
||
| 61 | $results = $this->performSearchIncludingFacets($selected, $model, $q); |
||
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | $results->setQuery($q); |
||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | // get suggestions |
||
| 71 | $factory = new SuggesterFactory(); |
||
| 72 | |||
| 73 | /** @var \Suilven\FreeTextSearch\Factory\Suggester $suggester */ |
||
| 74 | $suggester = $factory->getSuggester(); |
||
| 75 | |||
| 76 | // @todo this is returning blank |
||
| 77 | $suggester->setIndex($model->IndexToSearch); |
||
| 78 | $suggestions = $suggester->suggest($q); |
||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | /* |
||
| 83 | $facetted = isset($results['AllFacets']); |
||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | $targetFacet = new ArrayList(); |
||
| 88 | if (isset($model->ShowTagCloudFor)) { |
||
| 89 | // get the tag cloud from calculated facets, but if not calculated, ie the arrive on the page case, |
||
| 90 | // calculate them |
||
| 91 | if ($facetted) { |
||
| 92 | $facets = $results['AllFacets']; |
||
| 93 | } else { |
||
| 94 | $proxyResults = $this->performSearchIncludingFacets($selected, $model, $q); |
||
| 95 | $facets = $proxyResults['AllFacets']; |
||
| 96 | } |
||
| 97 | |||
| 98 | foreach ($facets as $facet) { |
||
| 99 | $name = $facet->getField('Name'); |
||
| 100 | if ($name === $model->ShowTagCloudFor) { |
||
| 101 | $targetFacet = $facet->getField('Facets'); |
||
| 102 | |||
| 103 | break; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $facetArray = $targetFacet->toArray(); |
||
| 108 | $minSize = 10; |
||
| 109 | $maxSize = 40; |
||
| 110 | $maxCount = 0; |
||
| 111 | foreach ($facetArray as $tag) { |
||
| 112 | $count = $tag['Count']; |
||
| 113 | $maxCount = $count > $maxCount |
||
| 114 | ? $count |
||
| 115 | : $maxCount; |
||
| 116 | } |
||
| 117 | |||
| 118 | $tagCloud = new ArrayList(); |
||
| 119 | foreach ($facetArray as $tag) { |
||
| 120 | $size = $minSize + ($maxSize - $minSize) * $tag['Count'] / $maxCount; |
||
| 121 | $size = \round($size); |
||
| 122 | $row = new ArrayData([ |
||
| 123 | 'Name' => $tag['Value'], |
||
| 124 | 'Size' => $size, |
||
| 125 | 'Params' => $tag['Params'], |
||
| 126 | ]); |
||
| 127 | $tagCloud->push($row); |
||
| 128 | } |
||
| 129 | |||
| 130 | $results['TagCloud'] = $tagCloud; |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | //for($i = 3; $i < 40; $i++) { |
||
| 135 | // echo "li.tag{$i} { font-size: {$i}px;};\n"; |
||
| 136 | //} |
||
| 137 | |||
| 138 | */ |
||
| 139 | |||
| 140 | |||
| 141 | // defer showing to the template level, still get facets, as this allows optionally for likes of a tag cloud |
||
| 142 | // $results['ShowAllIfEmptyQuery'] = $model->ShowAllIfEmptyQuery; |
||
| 143 | // $results['CleanedLink'] = $this->Link(); |
||
| 144 | |||
| 145 | $records = $results->getRecords(); |
||
| 146 | $newRecords = new ArrayList(); |
||
| 147 | foreach ($records as $record) { |
||
| 148 | $highsList = new ArrayList(); |
||
| 149 | $highlightsArray = $record->Highlights; |
||
| 150 | |||
| 151 | $keys = \array_keys($highlightsArray); |
||
| 152 | foreach ($keys as $highlightedField) { |
||
| 153 | foreach ($highlightsArray[$highlightedField] as $highlightsForField) { |
||
| 154 | $do = new DataObject(); |
||
| 155 | $do->Snippet = '...' . $highlightsForField . '...'; |
||
| 156 | |||
| 157 | $highsList->push($do); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | $record->Highlights = $highsList; |
||
| 164 | $newRecords->push($record); |
||
| 165 | } |
||
| 166 | |||
| 167 | return $this->customise(new ArrayData([ |
||
| 168 | 'NumberOfResults' => $results->getNumberOfResults(), |
||
| 169 | 'Query' => $results->getQuery(), |
||
| 170 | 'Records' => $newRecords, |
||
| 171 | 'Page' => $results->getPage(), |
||
| 172 | 'PageSize' => $results->getPageSize(), |
||
| 173 | 'Suggestions' => new ArrayList($results->getSuggestions()), |
||
| 174 | 'Time' => $results->getTime(), |
||
| 175 | ])); |
||
| 213 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths