YetiForceCompany/YetiForceCRM

View on GitHub
app/SystemWarnings/SystemRequirements/CronState.php

Summary

Maintainability
A
45 mins
Test Coverage
C
78%

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

    public function process(): void
    {
        $lastStart = \Settings_CronTasks_Module_Model::getInstance('Settings:CronTasks')->getLastCronStart();
        $checkTasks = (new \App\Db\Query())
            ->select(['id'])
Severity: Minor
Found in app/SystemWarnings/SystemRequirements/CronState.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 '38', column '22').
Open

        $checkTasks = (new \App\Db\Query())

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\Language' in method 'process'.
Open

            $this->description = \App\Language::translate($checkTasks ? 'LBL_CRON_DISABLED_DESC' : 'LBL_CRON_TASK_FAILED_DESC', 'Settings:SystemWarnings') . '<br />';

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

The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->status = 1;
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class '\App\Security\AdminAccess' in method 'process'.
Open

            if (!$checkTasks && \App\Security\AdminAccess::isPermitted('CronTasks')) {

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\Language' in method 'process'.
Open

                $this->linkTitle = \App\Language::translate('LBL_HOW_TO_ENABLE_CRON', 'Settings:SystemWarnings');

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\Config' in method 'process'.
Open

        $timeOut = round((\App\Config::main('maxExecutionCronTime') + 300) / 60);

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\Language' in method 'process'.
Open

                $this->linkTitle = \App\Language::translate('LBL_CRON_TASKS_LIST', 'Settings:SystemWarnings');

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 "Settings:SystemWarnings" 3 times.
Open

                $this->linkTitle = \App\Language::translate('LBL_CRON_TASKS_LIST', 'Settings:SystemWarnings');

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.

Reference to undeclared property \App\SystemWarnings\SystemRequirements\CronState->linkTitle
Open

                $this->linkTitle = \App\Language::translate('LBL_HOW_TO_ENABLE_CRON', 'Settings:SystemWarnings');

Reference to undeclared property \App\SystemWarnings\SystemRequirements\CronState->linkTitle
Open

                $this->linkTitle = \App\Language::translate('LBL_CRON_TASKS_LIST', 'Settings:SystemWarnings');

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

        $checkTasks = (new \App\Db\Query())

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

            ->where(['status' => 1, 'lastend' => null])

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

            if (!$checkTasks && \App\Security\AdminAccess::isPermitted('CronTasks')) {

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

     * @return void

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

                $this->link = 'index.php?module=CronTasks&parent=Settings&view=List';

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

     */

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

            $this->status = 0;

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 (0 === $lastStart || $checkTasks || strtotime("-{$timeOut} minutes") > $lastStart) {

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

    protected $title = 'LBL_CRON_STATE';

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

    /**

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

     * Checks if cron is active.

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

    {

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

                $this->linkTitle = \App\Language::translate('LBL_CRON_TASKS_LIST', 'Settings:SystemWarnings');

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

        } else {

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

            } elseif ($checkTasks) {

Line exceeds 120 characters; contains 166 characters
Open

            $this->description = \App\Language::translate($checkTasks ? 'LBL_CRON_DISABLED_DESC' : 'LBL_CRON_TASK_FAILED_DESC', 'Settings:SystemWarnings') . '<br />';

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

     */

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

    protected $priority = 9;

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

            ->from('vtiger_cron_task')

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 function process(): void

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

        $checkTasks = (new \App\Db\Query())

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

        $timeOut = round((\App\Config::main('maxExecutionCronTime') + 300) / 60);

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

            $this->status = 1;

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 (0 === $this->status) {

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

                $this->link = 'https://doc.yetiforce.com/administrator-guides/automation/cron/';

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

            $this->description = \App\Language::translate($checkTasks ? 'LBL_CRON_DISABLED_DESC' : 'LBL_CRON_TASK_FAILED_DESC', 'Settings:SystemWarnings') . '<br />';

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

     * @var int Warning priority code

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

        $lastStart = \Settings_CronTasks_Module_Model::getInstance('Settings:CronTasks')->getLastCronStart();

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

            ->limit(1)->exists();

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

                $this->linkTitle = \App\Language::translate('LBL_HOW_TO_ENABLE_CRON', 'Settings:SystemWarnings');

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

     * @var string Modal header title

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

    /**

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

            ->select(['id'])

There are no issues that match your filters.

Category
Status