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.
Completed
Push — master ( 221cb7...4c749c )
by Christian
02:31
created

AdminModel::resetUserSession()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4286
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
/**
4
 * Handles all data manipulation of the admin part
5
 */
6
class AdminModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
	/**
9
	 * Sets the deletion and suspension values
10
	 *
11
	 * @param $suspensionInDays
12
	 * @param $softDelete
13
	 * @param $userId
14
	 */
15
	public static function setAccountSuspensionAndDeletionStatus($suspensionInDays, $softDelete, $userId)
16
	{
17
		if ($suspensionInDays > 0) {
18
			$suspensionTime = time() + ($suspensionInDays * 60 * 60 * 24);
19
		} else {
20
			$suspensionTime = null;
21
		}
22
23
        // FYI "on" is what a checkbox delivers by default when submitted. Didn't know that for a long time :)
24
		if ($softDelete == "on") {
25
			$delete = 1;
26
		} else {
27
			$delete = 0;
28
		}
29
30
		// write the above info to the database
31
		self::writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete);
32
33
		// if suspension or deletion should happen, then also kick user out of the application instantly by resetting
34
		// the user's session :)
35
		if ($suspensionTime != null OR $delete = 1) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
36
			self::resetUserSession($userId);
37
		}
38
	}
39
40
	/**
41
	 * Simply write the deletion and suspension info for the user into the database, also puts feedback into session
42
	 *
43
	 * @param $userId
44
	 * @param $suspensionTime
45
	 * @param $delete
46
	 * @return bool
47
	 */
48
	private static function writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete)
49
	{
50
		$database = DatabaseFactory::getFactory()->getConnection();
51
52
		$query = $database->prepare("UPDATE users SET user_suspension_timestamp = :user_suspension_timestamp, user_deleted = :user_deleted  WHERE user_id = :user_id LIMIT 1");
53
		$query->execute(array(
54
				':user_suspension_timestamp' => $suspensionTime,
55
				':user_deleted' => $delete,
56
				':user_id' => $userId
57
		));
58
59
		if ($query->rowCount() == 1) {
60
			Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_SUSPENSION_DELETION_STATUS'));
61
			return true;
62
		}
63
	}
64
65
	/**
66
	 * Kicks the selected user out of the system instantly by resetting the user's session.
67
	 * This means, the user will be "logged out".
68
	 *
69
	 * @param $userId
70
	 * @return bool
71
	 */
72
	private static function resetUserSession($userId)
73
	{
74
		$database = DatabaseFactory::getFactory()->getConnection();
75
76
		$query = $database->prepare("UPDATE users SET session_id = :session_id  WHERE user_id = :user_id LIMIT 1");
77
		$query->execute(array(
78
				':session_id' => null,
79
				':user_id' => $userId
80
		));
81
82
		if ($query->rowCount() == 1) {
83
			Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_USER_SUCCESSFULLY_KICKED'));
84
			return true;
85
		}
86
	}
87
}
88