Failed Conditions
Push — rbac ( be68b4...52c28b )
by Michael
03:11
created

PageSendToUser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 21
c 2
b 0
f 0
dl 0
loc 40
ccs 0
cts 26
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A main() 0 33 5
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 Exception;
12
use Waca\DataObjects\User;
13
use Waca\Exceptions\ApplicationLogicException;
14
use Waca\Helpers\Logger;
15
use Waca\SessionAlert;
16
use Waca\WebRequest;
17
18
class PageSendToUser extends RequestActionBase
19
{
20
    /**
21
     * Main function for this page, when no specific actions are called.
22
     * @throws ApplicationLogicException
23
     * @throws Exception
24
     */
0 ignored issues
show
Coding Style introduced by
Expected 1 @throws tag(s) in function comment; 2 found
Loading history...
25
    protected function main()
26
    {
27
        $this->checkPosted();
28
        $database = $this->getDatabase();
29
        $request = $this->getRequest($database);
30
31
        if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
            throw new ApplicationLogicException('You don\'t have this request reserved!');
33
        }
34
35
        $username = WebRequest::postString('user');
36
        if ($username === null) {
37
            throw new ApplicationLogicException('User must be specified');
38
        }
39
40
        $user = User::getByUsername($username, $database);
41
        if ($user === false) {
42
            throw new ApplicationLogicException('User not found');
43
        }
44
45
        if (!$user->isActive()) {
46
            throw new ApplicationLogicException('User is currently not active on the tool');
47
        }
48
49
        $request->setReserved($user->getId());
50
        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
        $request->save();
52
53
        Logger::sendReservation($database, $request, $user);
54
        $this->getNotificationHelper()->requestReservationSent($request, $user);
55
        SessionAlert::success("Reservation sent successfully");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Reservation sent successfully does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
56
57
        $this->redirect('viewRequest', null, array('id' => $request->getId()));
58
    }
0 ignored issues
show
Coding Style introduced by
Expected //end main()
Loading history...
59
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
60