Conditions | 11 |
Paths | 49 |
Total Lines | 92 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
29 | protected function main() |
||
30 | { |
||
31 | $this->setHtmlTitle('Search'); |
||
32 | |||
33 | $database = $this->getDatabase(); |
||
34 | $currentUser = User::getCurrent($database); |
||
35 | |||
36 | $this->assign('canSearchByComment', $this->barrierTest('byComment', $currentUser)); |
||
37 | $this->assign('canSearchByEmail', $this->barrierTest('byEmail', $currentUser)); |
||
38 | $this->assign('canSearchByIp', $this->barrierTest('byIp', $currentUser)); |
||
39 | $this->assign('canSearchByName', $this->barrierTest('byName', $currentUser)); |
||
40 | $this->assign('canSeeNonConfirmed', $this->barrierTest('allowNonConfirmed', $currentUser)); |
||
41 | |||
42 | $this->setTemplate('search/main.tpl'); |
||
43 | |||
44 | // Dual-mode page |
||
45 | if (WebRequest::getString('type') !== null) { |
||
46 | $searchType = WebRequest::getString('type'); |
||
47 | $searchTerm = WebRequest::getString('term'); |
||
48 | |||
49 | $excludeNonConfirmed = true; |
||
50 | if ($this->barrierTest('allowNonConfirmed', $currentUser)) { |
||
51 | $excludeNonConfirmed = WebRequest::getBoolean('excludeNonConfirmed'); |
||
52 | } |
||
53 | |||
54 | $formParameters = [ |
||
55 | 'term' => $searchTerm, |
||
56 | 'type' => $searchType, |
||
57 | ]; |
||
58 | |||
59 | if ($excludeNonConfirmed) { |
||
60 | $formParameters['excludeNonConfirmed'] = true; |
||
61 | } |
||
62 | |||
63 | // FIXME: domains |
||
64 | $requestSearch = RequestSearchHelper::get($database, 1); |
||
65 | $this->setSearchHelper($requestSearch); |
||
66 | $this->setupLimits(); |
||
67 | |||
68 | $validationError = ""; |
||
69 | if (!$this->validateSearchParameters($searchType, $searchTerm, $validationError)) { |
||
70 | SessionAlert::error($validationError, "Search error"); |
||
71 | |||
72 | $this->setupPageData(0, $formParameters); |
||
73 | $this->assign('hasResultset', false); |
||
74 | |||
75 | return; |
||
76 | } |
||
77 | |||
78 | // searchType known to be sane from the validate step above |
||
79 | if (!$this->barrierTest('by' . ucfirst($searchType), User::getCurrent($this->getDatabase()))) { |
||
|
|||
80 | // only accessible by url munging, don't care about the UX |
||
81 | throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
||
82 | } |
||
83 | |||
84 | if ($excludeNonConfirmed) { |
||
85 | $requestSearch->withConfirmedEmail(); |
||
86 | } |
||
87 | |||
88 | switch ($searchType) { |
||
89 | case 'name': |
||
90 | $this->getNameSearchResults($requestSearch, $searchTerm); |
||
91 | break; |
||
92 | case 'email': |
||
93 | $this->getEmailSearchResults($requestSearch, $searchTerm); |
||
94 | break; |
||
95 | case 'ip': |
||
96 | $this->getIpSearchResults($requestSearch, $searchTerm); |
||
97 | break; |
||
98 | case 'comment': |
||
99 | $this->getCommentSearchResults($requestSearch, $searchTerm); |
||
100 | break; |
||
101 | } |
||
102 | |||
103 | /** @var Request[] $results */ |
||
104 | $results = $requestSearch->getRecordCount($count)->fetch(); |
||
105 | $this->setupPageData($count, $formParameters); |
||
106 | |||
107 | // deal with results |
||
108 | $this->assign('requests', $this->prepareRequestData($results)); |
||
109 | $this->assign('resultCount', count($results)); |
||
110 | $this->assign('hasResultset', true); |
||
111 | |||
112 | list($defaultSort, $defaultSortDirection) = WebRequest::requestListDefaultSort(); |
||
113 | $this->assign('defaultSort', $defaultSort); |
||
114 | $this->assign('defaultSortDirection', $defaultSortDirection); |
||
115 | } |
||
116 | else { |
||
117 | $this->assign('type', 'name'); |
||
118 | $this->assign('hasResultset', false); |
||
119 | $this->assign('limit', 50); |
||
120 | $this->assign('excludeNonConfirmed', true); |
||
121 | } |
||
220 |