YetiForceCompany/YetiForceCRM

View on GitHub
app/Fields/Token.php

Summary

Maintainability
A
45 mins
Test Coverage
A
100%

Function setTokens has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public static function setTokens(string $fieldName, string $moduleName)
    {
        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
        $fieldModel = $moduleModel->getFieldByName($fieldName);
        if ($fieldModel && $fieldModel->isActiveField()) {
Severity: Minor
Found in app/Fields/Token.php - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Missing class import via use statement (line '31', column '23').
Open

            $dataReader = (new \App\QueryGenerator($moduleName))
Severity: Minor
Found in app/Fields/Token.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 '46', column '9').
Open

            (new \App\BatchMethod(['method' => __METHOD__, 'params' => [$fieldName, $moduleName, time()]]))->save();
Severity: Minor
Found in app/Fields/Token.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\Encryption' in method 'generateToken'.
Open

        return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
Severity: Minor
Found in app/Fields/Token.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 '\Vtiger_Record_Model' in method 'setTokens'.
Open

                $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
Severity: Minor
Found in app/Fields/Token.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 '\Vtiger_Module_Model' in method 'setTokens'.
Open

        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
Severity: Minor
Found in app/Fields/Token.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

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

        return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
Severity: Critical
Found in app/Fields/Token.php by phan

Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            $dataReader = (new \App\QueryGenerator($moduleName))
Severity: Critical
Found in app/Fields/Token.php by phan

Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            $dataReader = (new \App\QueryGenerator($moduleName))
Severity: Critical
Found in app/Fields/Token.php by phan

Call to undeclared method \Vtiger_Base_UIType::generateToken
Open

                $token = $fieldModel->getUITypeModel()->generateToken();
Severity: Critical
Found in app/Fields/Token.php by phan

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

     *
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     * Sets token data.
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

        if ($fieldModel && $fieldModel->isActiveField()) {
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

            $dataReader = (new \App\QueryGenerator($moduleName))
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     * @param string $fieldName
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                $recordModel->set($fieldModel->getName(), $token)->setDataForSave([$fieldModel->getTableName() => [$fieldModel->getColumnName() => $token]])->save();
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

Line exceeds 120 characters; contains 165 characters
Open

                $recordModel->set($fieldModel->getName(), $token)->setDataForSave([$fieldModel->getTableName() => [$fieldModel->getColumnName() => $token]])->save();
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     * @param string $moduleName
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                ->query();
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     * Generate token.
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                if (!$limit) {
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

        return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                ->addCondition($fieldModel->getName(), '', 'y')
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    public static function setTokens(string $fieldName, string $moduleName)
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

            (new \App\BatchMethod(['method' => __METHOD__, 'params' => [$fieldName, $moduleName, time()]]))->save();
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     * @return string
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    public static function generateToken(): string
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

            $limit = 5000;
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                ->createQuery()
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                ->createCommand()
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                ->setFields(['id'])
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                    break;
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

        $fieldModel = $moduleModel->getFieldByName($fieldName);
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                $token = $fieldModel->getUITypeModel()->generateToken();
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                }
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

            while ($recordId = $dataReader->readColumn(0)) {
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

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

                --$limit;
Severity: Minor
Found in app/Fields/Token.php by phpcodesniffer

There are no issues that match your filters.

Category
Status