Failed Conditions
Push — newinternal ( b66232...216d62 )
by Simon
16:33 queued 06:35
created

RequestActionBase::enqueueWelcomeTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 10
loc 10
ccs 0
cts 0
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
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\RequestAction;
10
11
use Waca\Background\Task\WelcomeUserTask;
12
use Waca\DataObjects\JobQueue;
13
use Waca\DataObjects\Request;
14
use Waca\DataObjects\User;
15
use Waca\Exceptions\ApplicationLogicException;
16
use Waca\PdoDatabase;
17
use Waca\Tasks\InternalPageBase;
18
use Waca\WebRequest;
19
20
abstract class RequestActionBase extends InternalPageBase
21
{
22
    /**
23
     * @param PdoDatabase $database
24
     *
25
     * @return Request
26
     * @throws ApplicationLogicException
27
     */
28
    protected function getRequest(PdoDatabase $database)
29
    {
30
        $requestId = WebRequest::postInt('request');
31
        if ($requestId === null) {
32
            throw new ApplicationLogicException('Request ID not found');
33
        }
34
35
        /** @var Request $request */
36
        $request = Request::getById($requestId, $database);
37
38
        if ($request === false) {
39
            throw new ApplicationLogicException('Request not found');
40
        }
41
42
        return $request;
43
    }
44
45
    final protected function checkPosted()
46
    {
47
        // if the request was not posted, send the user away.
48
        if (!WebRequest::wasPosted()) {
49
            throw new ApplicationLogicException('This page does not support GET methods.');
50
        }
51
52
        // validate the CSRF token
53
        $this->validateCSRFToken();
54
    }
55
56
    /**
57
     * @param Request     $request
58
     * @param             $parentTaskId
59
     * @param User        $user
60
     * @param PdoDatabase $database
61
     */
62 View Code Duplication
    protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $welcomeTask = new JobQueue();
65
        $welcomeTask->setTask(WelcomeUserTask::class);
66
        $welcomeTask->setRequest($request->getId());
67
        $welcomeTask->setParent($parentTaskId);
68
        $welcomeTask->setTriggerUserId($user->getId());
69
        $welcomeTask->setDatabase($database);
70
        $welcomeTask->save();
71
    }
72
}