| Conditions | 3 |
| Paths | 4 |
| Total Lines | 62 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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); |
||
| 29 | public function search(?string $q): SearchResults |
||
| 30 | { |
||
| 31 | $startTime = \microtime(true); |
||
| 32 | $client = new Client(); |
||
| 33 | $manticoreClient = $client->getConnection(); |
||
| 34 | |||
| 35 | $searcher = new Search($manticoreClient); |
||
| 36 | $searcher->setIndex($this->indexName); |
||
| 37 | |||
| 38 | $searcher->limit($this->pageSize); |
||
| 39 | $offset=$this->pageSize * ($this->page-1); |
||
| 40 | $searcher->offset($offset); |
||
| 41 | |||
| 42 | $indexes = new Indexes(); |
||
| 43 | $index = $indexes->getIndex($this->indexName); |
||
| 44 | |||
| 45 | $searcher->highlight( |
||
| 46 | [], |
||
| 47 | ['pre_tags' => '<b>', 'post_tags'=>'</b>'] |
||
| 48 | ); |
||
| 49 | |||
| 50 | $q = \is_null($q) |
||
| 51 | ? '' |
||
| 52 | : $q; |
||
| 53 | |||
| 54 | $manticoreResult = $searcher->search($q)->get(); |
||
| 55 | $allFields = $this->getAllFields($index); |
||
| 56 | |||
| 57 | |||
| 58 | $ssResult = new ArrayList(); |
||
| 59 | while ($manticoreResult->valid()) { |
||
| 60 | $hit = $manticoreResult->current(); |
||
| 61 | $source = $hit->getData(); |
||
| 62 | $ssDataObject = new DataObject(); |
||
| 63 | |||
| 64 | $this->populateSearchResult($ssDataObject, $allFields, $source); |
||
| 65 | |||
| 66 | // manticore lowercases fields, so as above normalize them back to the SS fieldnames |
||
| 67 | $highlights = $hit->getHighlight(); |
||
| 68 | $fieldsToHighlight = $index->getHighlightedFields(); |
||
| 69 | $this->addHighlights($ssDataObject, $allFields, $highlights, $fieldsToHighlight); |
||
| 70 | |||
| 71 | $ssDataObject->ID = $hit->getId(); |
||
| 72 | $ssResult->push($ssDataObject); |
||
| 73 | $manticoreResult->next(); |
||
| 74 | } |
||
| 75 | |||
| 76 | // we now need to standardize the output returned |
||
| 77 | |||
| 78 | $searchResults = new SearchResults(); |
||
| 79 | $searchResults->setRecords($ssResult); |
||
| 80 | $searchResults->setPage($this->page); |
||
| 81 | $searchResults->setPageSize($this->pageSize); |
||
| 82 | $searchResults->setQuery($q); |
||
| 83 | $searchResults->setTotalNumberOfResults($manticoreResult->getTotal()); |
||
| 84 | |||
| 85 | $endTime = \microtime(true); |
||
| 86 | $delta = $endTime - $startTime; |
||
| 87 | $delta = \round(1000*$delta)/1000; |
||
| 88 | $searchResults->setTime($delta); |
||
| 89 | |||
| 90 | return $searchResults; |
||
| 91 | } |
||
| 199 |