logoutCurrentUser accesses the super-global variable $_COOKIE. Open
public static function logoutCurrentUser()
{
if ($sessionId = $_COOKIE['roundcube_sessid'] ?? null) {
$cookie = session_get_cookie_params();
$secure = $cookie['secure'] || \App\RequestUtil::isHttps();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Missing class import via use statement (line '45', column '26'). Open
$roundCubeUsers = (new \App\Db\Query())->select(['user_id'])
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '48', column '22'). Open
$dataReader = (new \App\Db\Query())->from('roundcube_session')->createCommand()->query();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\App\RequestUtil' in method 'logoutCurrentUser'. Open
$secure = $cookie['secure'] || \App\RequestUtil::isHttps();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid assigning values to variables in if clauses and the like (line '24', column '7'). Open
public static function logoutCurrentUser()
{
if ($sessionId = $_COOKIE['roundcube_sessid'] ?? null) {
$cookie = session_get_cookie_params();
$secure = $cookie['secure'] || \App\RequestUtil::isHttps();
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\Session\File' in method 'getSessId'. Open
$sessData = \App\Session\File::unserialize(base64_decode($row['vars']));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "sess_id" 3 times. Open
->delete('roundcube_session', ['sess_id' => $sessionId])
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "roundcube_session" 3 times. Open
->delete('roundcube_session', ['sess_id' => $sessionId])
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "user_id" 3 times. Open
$roundCubeUsers = (new \App\Db\Query())->select(['user_id'])
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Call to undeclared method \App\Db\Query::from
Open
$dataReader = (new \App\Db\Query())->from('roundcube_session')->createCommand()->query();
- Exclude checks
@throws type of logutUserById
has undeclared type \yii\db\Exception
(Did you mean class \Exception) Open
public static function logutUserById(int $userId)
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()
- Exclude checks
@throws type of logoutCurrentUser
has undeclared type \yii\db\Exception
(Did you mean class \Exception) Open
public static function logoutCurrentUser()
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$roundCubeUsers = (new \App\Db\Query())->select(['user_id'])
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class OSSMail_Logout_Model
- Exclude checks
The class OSSMail_Logout_Model is not named in CamelCase. Open
class OSSMail_Logout_Model
{
/**
* Logout current user.
*
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId Crm user ID
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \yii\db\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$arraySess[] = $row['sess_id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$secure = $cookie['secure'] || \App\RequestUtil::isHttps();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Logout current user.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('roundcube_users')->where(['crm_user_id' => $userId])->column();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$arraySess = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exp = time() - 3600;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->delete('roundcube_session', ['sess_id' => $sessionId])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getSessId(int $userId)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function logoutCurrentUser()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($sessionId = $_COOKIE['roundcube_sessid'] ?? null) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->from('roundcube_session')->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sessData = \App\Session\File::unserialize(base64_decode($row['vars']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
setcookie('roundcube_sessid', '', $exp, $cookie['path'], $cookie['domain'], $secure, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get a list of sessions by Crm user ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Log out user by ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \yii\db\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$roundCubeUsers = (new \App\Db\Query())->select(['user_id'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($sessData['user_id']) && \in_array((int) $sessData['user_id'], $roundCubeUsers)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cookie = session_get_cookie_params();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function logutUserById(int $userId)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $arraySess;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sessId = static::getSessId($userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
setcookie('roundcube_sessauth', '', $exp, $cookie['path'], $cookie['domain'], $secure, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($sessId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->delete('roundcube_session', ['sess_id' => $sessId])
- Exclude checks
Class name "OSSMail_Logout_Model" is not in camel caps format Open
class OSSMail_Logout_Model
- Exclude checks