YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSMail/models/Logout.php

Summary

Maintainability
A
0 mins
Test Coverage

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();
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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'])
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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();
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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();
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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();
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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']));
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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])
Severity: Critical
Found in modules/OSSMail/models/Logout.php by sonar-php

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])
Severity: Critical
Found in modules/OSSMail/models/Logout.php by sonar-php

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'])
Severity: Critical
Found in modules/OSSMail/models/Logout.php by sonar-php

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();
Severity: Critical
Found in modules/OSSMail/models/Logout.php by phan

@throws type of logutUserById has undeclared type \yii\db\Exception (Did you mean class \Exception)
Open

    public static function logutUserById(int $userId)
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phan

Call to undeclared method \App\Db::createCommand
Open

            \App\Db::getInstance()->createCommand()
Severity: Critical
Found in modules/OSSMail/models/Logout.php by phan

@throws type of logoutCurrentUser has undeclared type \yii\db\Exception (Did you mean class \Exception)
Open

    public static function logoutCurrentUser()
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phan

Call to undeclared method \App\Db\Query::select
Open

        $roundCubeUsers = (new \App\Db\Query())->select(['user_id'])
Severity: Critical
Found in modules/OSSMail/models/Logout.php by phan

Call to undeclared method \App\Db::createCommand
Open

            \App\Db::getInstance()->createCommand()
Severity: Critical
Found in modules/OSSMail/models/Logout.php by phan

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class OSSMail_Logout_Model

The class OSSMail_Logout_Model is not named in CamelCase.
Open

class OSSMail_Logout_Model
{
    /**
     * Logout current user.
     *
Severity: Minor
Found in modules/OSSMail/models/Logout.php by phpmd

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

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int $userId Crm user ID

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \yii\db\Exception

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                $arraySess[] = $row['sess_id'];

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

            $secure = $cookie['secure'] || \App\RequestUtil::isHttps();

Spaces must be used to indent lines; tabs are not allowed
Open

     * Logout current user.

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            ->from('roundcube_users')->where(['crm_user_id' => $userId])->column();

Spaces must be used to indent lines; tabs are not allowed
Open

        $arraySess = [];

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            $exp = time() - 3600;

Spaces must be used to indent lines; tabs are not allowed
Open

                ->delete('roundcube_session', ['sess_id' => $sessionId])

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function getSessId(int $userId)

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            \App\Db::getInstance()->createCommand()

Spaces must be used to indent lines; tabs are not allowed
Open

                ->execute();

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function logoutCurrentUser()

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($sessionId = $_COOKIE['roundcube_sessid'] ?? null) {

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string[]

Spaces must be used to indent lines; tabs are not allowed
Open

        $dataReader = (new \App\Db\Query())->from('roundcube_session')->createCommand()->query();

Spaces must be used to indent lines; tabs are not allowed
Open

            $sessData = \App\Session\File::unserialize(base64_decode($row['vars']));

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

            setcookie('roundcube_sessid', '', $exp, $cookie['path'], $cookie['domain'], $secure, true);

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get a list of sessions by Crm user ID.

Spaces must be used to indent lines; tabs are not allowed
Open

     * Log out user by ID.

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $dataReader->close();

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws \yii\db\Exception

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $roundCubeUsers = (new \App\Db\Query())->select(['user_id'])

Spaces must be used to indent lines; tabs are not allowed
Open

            if (isset($sessData['user_id']) && \in_array((int) $sessData['user_id'], $roundCubeUsers)) {

Spaces must be used to indent lines; tabs are not allowed
Open

            $cookie = session_get_cookie_params();

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param int $userId

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function logutUserById(int $userId)

Spaces must be used to indent lines; tabs are not allowed
Open

        return $arraySess;

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $sessId = static::getSessId($userId);

Spaces must be used to indent lines; tabs are not allowed
Open

            setcookie('roundcube_sessauth', '', $exp, $cookie['path'], $cookie['domain'], $secure, true);

Spaces must be used to indent lines; tabs are not allowed
Open

        while ($row = $dataReader->read()) {

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

                ->execute();

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($sessId) {

Spaces must be used to indent lines; tabs are not allowed
Open

            \App\Db::getInstance()->createCommand()

Spaces must be used to indent lines; tabs are not allowed
Open

                ->delete('roundcube_session', ['sess_id' => $sessId])

Class name "OSSMail_Logout_Model" is not in camel caps format
Open

class OSSMail_Logout_Model

There are no issues that match your filters.

Category
Status