| Conditions | 8 |
| Paths | 12 |
| Total Lines | 67 |
| Code Lines | 46 |
| 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 |
||
| 28 | protected function main() |
||
| 29 | { |
||
| 30 | $this->setHtmlTitle('Search'); |
||
| 31 | |||
| 32 | // Dual-mode page |
||
| 33 | if (WebRequest::getString('type') !== null) { |
||
| 34 | $searchType = WebRequest::getString('type'); |
||
| 35 | $searchTerm = WebRequest::getString('term'); |
||
| 36 | $excludeNonConfirmed = WebRequest::getBoolean('excludeNonConfirmed'); |
||
| 37 | |||
| 38 | $validationError = ""; |
||
| 39 | if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
||
| 40 | SessionAlert::error($validationError, "Search error"); |
||
| 41 | |||
| 42 | $this->assign('term', $searchTerm); |
||
| 43 | $this->assign('target', $searchType); |
||
| 44 | $this->assign('excludeNonConfirmed', $excludeNonConfirmed); |
||
| 45 | $this->assign('hasResultset', false); |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | $requestSearch = RequestSearchHelper::get($this->getDatabase()); |
||
| 50 | |||
| 51 | $this->setSearchHelper($requestSearch); |
||
| 52 | $this->setupLimits(); |
||
| 53 | |||
| 54 | if ($excludeNonConfirmed) { |
||
| 55 | $requestSearch->withConfirmedEmail(); |
||
| 56 | } |
||
| 57 | |||
| 58 | switch ($searchType) { |
||
| 59 | case 'name': |
||
| 60 | $this->getNameSearchResults($requestSearch, $searchTerm); |
||
| 61 | break; |
||
| 62 | case 'email': |
||
| 63 | $this->getEmailSearchResults($requestSearch, $searchTerm); |
||
| 64 | break; |
||
| 65 | case 'ip': |
||
| 66 | $this->getIpSearchResults($requestSearch, $searchTerm); |
||
| 67 | break; |
||
| 68 | case 'comment': |
||
| 69 | $this->getCommentSearchResults($requestSearch, $searchTerm); |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** @var Request[] $results */ |
||
| 74 | $results = $requestSearch->getRecordCount($count)->fetch(); |
||
| 75 | |||
| 76 | $this->setupPageData($count, [ |
||
| 77 | 'term' => $searchTerm, |
||
| 78 | 'type' => $searchType, |
||
| 79 | 'excludeNonConfirmed' => $excludeNonConfirmed, |
||
| 80 | ]); |
||
| 81 | |||
| 82 | // deal with results |
||
| 83 | $this->assign('requests', $this->prepareRequestData($results)); |
||
| 84 | $this->assign('resultCount', count($results)); |
||
| 85 | $this->assign('hasResultset', true); |
||
| 86 | |||
| 87 | $this->setTemplate('search/main.tpl'); |
||
| 88 | } |
||
| 89 | else { |
||
| 90 | $this->assign('target', 'name'); |
||
| 91 | $this->assign('hasResultset', false); |
||
| 92 | $this->assign('limit', 50); |
||
| 93 | $this->assign('excludeNonConfirmed', true); |
||
| 94 | $this->setTemplate('search/main.tpl'); |
||
| 95 | } |
||
| 189 |