GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UserRoleModel::saveRoleToDatabase()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * Class UserRoleModel
5
 *
6
 * This class contains everything that is related to up- and downgrading accounts.
7
 */
8
class UserRoleModel
9
{
10
    /**
11
     * Upgrades / downgrades the user's account. Currently it's just the field user_account_type in the database that
12
     * can be 1 or 2 (maybe "basic" or "premium"). Put some more complex stuff in here, maybe a pay-process or whatever
13
     * you like.
14
     *
15
     * @param $type
16
     *
17
     * @return bool
18
     */
19
    public static function changeUserRole($type)
20
    {
21
        if (!$type) {
22
            return false;
23
        }
24
25
        // save new role to database
26
        if (self::saveRoleToDatabase($type)) {
27
            Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_SUCCESSFUL'));
28
            return true;
29
        } else {
30
            Session::add('feedback_negative', Text::get('FEEDBACK_ACCOUNT_TYPE_CHANGE_FAILED'));
31
            return false;
32
        }
33
    }
34
35
    /**
36
     * Writes the new account type marker to the database and to the session
37
     *
38
     * @param $type
39
     *
40
     * @return bool
41
     */
42
    public static function saveRoleToDatabase($type)
43
    {
44
        // if $type is not 1 or 2
45
        if (!in_array($type, [1, 2])) {
46
            return false;
47
        }
48
49
        $database = DatabaseFactory::getFactory()->getConnection();
50
51
        $query = $database->prepare("UPDATE users SET user_account_type = :new_type WHERE user_id = :user_id LIMIT 1");
52
        $query->execute(array(
53
            ':new_type' => $type,
54
            ':user_id' => Session::get('user_id')
55
        ));
56
57
        if ($query->rowCount() == 1) {
58
            // set account type in session
59
            Session::set('user_account_type', $type);
60
            return true;
61
        }
62
63
        return false;
64
    }
65
}
66