Passed
Push — newinternal-releasecandidate ( e5ef47...40acd0 )
by Simon
08:47
created

PageExpandedRequestList::main()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 52
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 52
rs 9.0968
cc 5
nc 5
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Pages;
10
11
use PDO;
12
use Waca\DataObjects\Request;
13
use Waca\Fragments\RequestListData;
14
use Waca\Tasks\InternalPageBase;
15
use Waca\WebRequest;
16
17
class PageExpandedRequestList extends InternalPageBase
18
{
19
    use RequestListData;
20
21
    /**
22
     * Main function for this page, when no specific actions are called.
23
     * @return void
24
     * @todo This is very similar to the PageMain code, we could probably generalise this somehow
25
     */
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
        }
79
    }
80
}
81