YetiForceCompany/YetiForceCRM

View on GitHub
app/Utils/Tokens.php

Summary

Maintainability
A
0 mins
Test Coverage
F
55%

The method get has a boolean flag argument $remove, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function get(string $uid, bool $remove = true): ?array
Severity: Minor
Found in app/Utils/Tokens.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

Missing class import via use statement (line '88', column '15').
Open

        $row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
Severity: Minor
Found in app/Utils/Tokens.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 '50', column '14').
Open

            throw new \App\Exceptions\AppException("The method `$method` does not exist");
Severity: Minor
Found in app/Utils/Tokens.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\Db' in method 'get'.
Open

        $row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
Severity: Minor
Found in app/Utils/Tokens.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 using static access to class '\App\Json' in method 'generate'.
Open

            'params' => \App\Json::encode($params),
Severity: Minor
Found in app/Utils/Tokens.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 using static access to class '\App\Encryption' in method 'generateUid'.
Open

        $uid = \App\Encryption::generatePassword(64);
Severity: Minor
Found in app/Utils/Tokens.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 using static access to class '\App\Json' in method 'get'.
Open

            $row['params'] = \App\Json::decode($row['params']);
Severity: Minor
Found in app/Utils/Tokens.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 using static access to class '\App\User' in method 'generate'.
Open

            'created_by_user' => \App\User::getCurrentUserRealId(),
Severity: Minor
Found in app/Utils/Tokens.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 "params" 4 times.
Open

            return \call_user_func($tokenData['method'], $tokenData['params']);
Severity: Critical
Found in app/Utils/Tokens.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 "expiration_date" 3 times.
Open

            'expiration_date' => $expirationDate,
Severity: Critical
Found in app/Utils/Tokens.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 "s_#__tokens" 3 times.
Open

        \App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
Severity: Critical
Found in app/Utils/Tokens.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 "admin" 3 times.
Open

        \App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
Severity: Critical
Found in app/Utils/Tokens.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::createCommand
Open

        \App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
Severity: Critical
Found in app/Utils/Tokens.php by phan

Call to method generatePassword from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

        $uid = \App\Encryption::generatePassword(64);
Severity: Critical
Found in app/Utils/Tokens.php by phan

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

        $row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
Severity: Critical
Found in app/Utils/Tokens.php by phan

Call to method getCurrentUserRealId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            'created_by_user' => \App\User::getCurrentUserRealId(),
Severity: Critical
Found in app/Utils/Tokens.php by phan

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

        \App\Db::getInstance('admin')->createCommand()->delete('s_#__tokens', ['uid' => $uid])->execute();
Severity: Critical
Found in app/Utils/Tokens.php by phan

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        ])->execute();
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * Generate uid function.
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'params' => \App\Json::encode($params),
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @return string
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * Get token detail.
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        $row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

Line exceeds 120 characters; contains 126 characters
Open

        $row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        return false;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @return string
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    public static function generate(string $method, array $params, string $expirationDate = null): string
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        \App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * Execute token method.
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'expiration_date' => $expirationDate,
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param string     $uid
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @return bool
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    public static function execute(string $uid, array $tokenData = null): bool
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'created_by_user' => \App\User::getCurrentUserRealId(),
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param string $uid
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param string      $method         Method name
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param array       $params
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    private static function generateUid(): string
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if ($remove) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @return void
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        \App\Db::getInstance('admin')->createCommand()->delete('s_#__tokens', ['uid' => $uid])->execute();
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            $tokenData = self::get($uid);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            throw new \App\Exceptions\AppException("The method `$method` does not exist");
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'created_date' => date('Y-m-d H:i:s'),
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if (!empty($row['expiration_date']) && strtotime($row['expiration_date']) < time()) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    public static function delete(string $uid): void
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if (null !== $tokenData) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            return \call_user_func($tokenData['method'], $tokenData['params']);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if (!\is_callable($method) && !class_exists($method)) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        $uid = self::generateUid();
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param bool   $remove
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @return array|null
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param array|null $tokenData
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * Generate token.
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'method' => $method,
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    public static function get(string $uid, bool $remove = true): ?array
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            $row = null;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if ($row) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        return $row;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            $row['params'] = \App\Json::decode($row['params']);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if (null !== self::get($uid)) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            return self::generateUid();
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            self::delete($uid);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        if (null === $tokenData) {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param string|null $expirationDate Date and time until which the token is valid
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            'uid' => $uid,
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        return $uid;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * @param string $uid
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        $uid = \App\Encryption::generatePassword(64);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

            self::delete($uid);
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

        return $uid;
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

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

     * Delete token.
Severity: Minor
Found in app/Utils/Tokens.php by phpcodesniffer

There are no issues that match your filters.

Category
Status