| Conditions | 5 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 26 | protected function main() |
||
| 27 | { |
||
| 28 | $config = $this->getSiteConfiguration(); |
||
| 29 | |||
| 30 | $requestedStatus = WebRequest::getString('status'); |
||
| 31 | $requestStates = $config->getRequestStates(); |
||
| 32 | |||
| 33 | if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
||
| 34 | |||
| 35 | $this->assignCSRFToken(); |
||
| 36 | |||
| 37 | $database = $this->getDatabase(); |
||
| 38 | |||
| 39 | $help = $requestStates[$requestedStatus]['queuehelp']; |
||
| 40 | $this->assign('queuehelp', $help); |
||
| 41 | |||
| 42 | if ($config->getEmailConfirmationEnabled()) { |
||
| 43 | $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
||
| 44 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
||
| 45 | } |
||
| 46 | else { |
||
| 47 | $query = "SELECT * FROM request WHERE status = :type;"; |
||
| 48 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
||
| 49 | } |
||
| 50 | |||
| 51 | $statement = $database->prepare($query); |
||
| 52 | $totalRequestsStatement = $database->prepare($totalQuery); |
||
| 53 | |||
| 54 | $statement->bindValue(":type", $requestedStatus); |
||
| 55 | $statement->execute(); |
||
| 56 | |||
| 57 | $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
||
| 58 | |||
| 59 | /** @var Request $req */ |
||
| 60 | foreach ($requests as $req) { |
||
| 61 | $req->setDatabase($database); |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->assign('requests', $this->prepareRequestData($requests)); |
||
| 65 | $this->assign('header', $requestedStatus); |
||
| 66 | $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
||
| 67 | $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
||
| 68 | |||
| 69 | $totalRequestsStatement->bindValue(':type', $requestedStatus); |
||
| 70 | $totalRequestsStatement->execute(); |
||
| 71 | $totalRequests = $totalRequestsStatement->fetchColumn(); |
||
| 72 | $totalRequestsStatement->closeCursor(); |
||
| 73 | $this->assign('totalRequests', $totalRequests); |
||
| 74 | |||
| 75 | |||
| 76 | $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
||
| 77 | $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
||
| 78 | } |
||
| 81 |