YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Vtiger/models/Tracker.php

Summary

Maintainability
A
1 hr
Test Coverage
B
85%

Function addDetail has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function addDetail($prev, $post)
    {
        if (self::$lockTrack) {
            return true;
        }
Severity: Minor
Found in modules/Settings/Vtiger/models/Tracker.php - About 35 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

Function addBasic has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public static function addBasic(string $type): void
    {
        $db = App\Db::getInstance('log');
        if ('view' == $type && App\Request::_isAjax()) {
            self::lockTracking();
Severity: Minor
Found in modules/Settings/Vtiger/models/Tracker.php - About 25 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

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

    public static function lockTracking($lock = true)

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

Avoid using static access to class '\App\Request' in method 'addBasic'.
Open

            'module_name' => \App\Request::_get('module'),

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\Db' in method 'addDetail'.
Open

        $db = App\Db::getInstance('log');

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 '42', column '7').
Open

    public static function addBasic(string $type): void
    {
        $db = App\Db::getInstance('log');
        if ('view' == $type && App\Request::_isAjax()) {
            self::lockTracking();

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\Db' in method 'addBasic'.
Open

        $db = App\Db::getInstance('log');

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\Request' in method 'addBasic'.
Open

        if ($mode = \App\Request::_getMode()) {

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\Request' in method 'addBasic'.
Open

        if ('view' == $type && App\Request::_isAjax()) {

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 'addBasic'.
Open

            'user_id' => \App\User::getCurrentUserId(),

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 getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            'user_id' => \App\User::getCurrentUserId(),
Severity: Critical
Found in modules/Settings/Vtiger/models/Tracker.php by phan

Assigning int to property but \Settings_Vtiger_Tracker_Model::$recordId is string
Open

            self::$recordId = $record;

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

        $insertedInfo = $db->createCommand()->insert('l_#__settings_tracker_basic', [
Severity: Critical
Found in modules/Settings/Vtiger/models/Tracker.php by phan

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

            $db->createCommand()->insert('l_#__settings_tracker_detail', [
Severity: Critical
Found in modules/Settings/Vtiger/models/Tracker.php by phan

Assigning string to property but \Settings_Vtiger_Tracker_Model::$id is false
Open

            self::$id = $db->getLastInsertID('l_#__settings_tracker_basic_id_seq');

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

        App\Db::getInstance('log')->createCommand()
Severity: Critical
Found in modules/Settings/Vtiger/models/Tracker.php by phan

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

class Settings_Vtiger_Tracker_Model

The class Settings_Vtiger_Tracker_Model is not named in CamelCase.
Open

class Settings_Vtiger_Tracker_Model
{
    private static $recordId = '';
    private static $lockTrack = false;
    private static $id = false;

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Avoid variables with short names like $id. Configured minimum length is 3.
Open

    private static $id = false;

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $db. Configured minimum length is 3.
Open

        $db = App\Db::getInstance('log');

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $db. Configured minimum length is 3.
Open

        $db = App\Db::getInstance('log');

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

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

    private static $id = false;

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

        if (false !== self::$id || self::$lockTrack) {

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

            return;

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

            'user_id' => \App\User::getCurrentUserId(),

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

            'record_id' => self::$recordId ? self::$recordId : 0,

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

        foreach ($post as $key => $value) {

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

            }

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

    private static $recordId = '';

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

            'module_name' => \App\Request::_get('module'),

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

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

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

                'prev_value' => $prev[$key] ?? '',

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

    public static function lockTracking($lock = true)

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

    }

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

        $action = \App\Process::$processType . ':' . \App\Process::$processName;

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

            'date' => date('Y-m-d H:i:s'),

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

            self::$id = $db->getLastInsertID('l_#__settings_tracker_basic_id_seq');

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

    public static function changeType($type)

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

                continue;

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

    }

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

        'save' => 2,

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

            self::lockTracking();

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

            'type' => self::$types[$type],

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

        if (self::$lockTrack) {

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

        self::$lockTrack = $lock;

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

            ->execute();

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

            return true;

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

            self::$recordId = $record;

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

        'view' => 1,

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

        if ('view' == $type && App\Request::_isAjax()) {

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 (false !== self::$id) {

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

                'post_value' => null === $value ? '' : $value,

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

    public static function addDetail($prev, $post)

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

                'field' => $key,

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

        }

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

                'id' => self::$id,

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

        if ($mode = \App\Request::_getMode()) {

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

        $insertedInfo = $db->createCommand()->insert('l_#__settings_tracker_basic', [

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

            'action' => $action,

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 (isset($prev[$key]) && $value == $prev[$key]) {

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

    private static $lockTrack = false;

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

    private static $types = [

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 (1 === $insertedInfo) {

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

            $db->createCommand()->insert('l_#__settings_tracker_detail', [

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

        'delete' => 3,

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

     * @param string $type

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

     */

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

        $db = App\Db::getInstance('log');

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

            self::addBasic('save');

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

     * Adding basic information about tracking.

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

        $db = App\Db::getInstance('log');

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

            ->update('l_#__settings_tracker_basic', ['type' => self::$types[$type]], ['id' => [self::$id]])

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

    public static function addBasic(string $type): void

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

            $action .= ':' . $mode;

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 setRecordId($record)

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

        if (empty(self::$recordId)) {

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

class Settings_Vtiger_Tracker_Model

There are no issues that match your filters.

Category
Status