YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/helpers/ListUpdatedRecord.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method getListRecord has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function getListRecord($module, array $columnList, $limit)
    {
        $moduleList = [];
        $recordList = [];
        if (!$module) {
Severity: Minor
Found in modules/Vtiger/helpers/ListUpdatedRecord.php - About 1 hr to fix

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

        public static function getListRecord($module, array $columnList, $limit)
        {
            $moduleList = [];
            $recordList = [];
            if (!$module) {
    Severity: Minor
    Found in modules/Vtiger/helpers/ListUpdatedRecord.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

    Missing class import via use statement (line '32', column '22').
    Open

            $dataReader = (new \App\Db\Query())->select($select)->from('vtiger_crmentity')

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

                $moduleList = (new \App\Db\Query())->select(['name'])

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

                $row['setype'] = \App\Language::translate($row['setype'], $row['setype']);

    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\Module' in method 'getListRecord'.
    Open

            $select['smownerid'] = \App\Module::getSqlForNameInDisplayFormat('Users');

    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 getListRecord uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $moduleList[] = $module;
            }

    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

    Define a constant instead of duplicating this literal "setype" 4 times.
    Open

                ->where(['was_read' => 0, 'vtiger_crmentity.deleted' => 0, 'setype' => $moduleList])

    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 "smownerid" 3 times.
    Open

            if (!\in_array('smownerid', $columnList)) {

    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::select
    Open

            $dataReader = (new \App\Db\Query())->select($select)->from('vtiger_crmentity')

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

                $moduleList = (new \App\Db\Query())->select(['name'])

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

    class ListUpdatedRecord

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

                    ->andWhere(['<>', 'presence', 1])

    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

            }

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

                $moduleList[] = $module;

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

            return $recordList;

    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 false;

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

                $moduleList = (new \App\Db\Query())->select(['name'])

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

            $select = array_values($columnList);

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

                ->limit($limit)

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

            }

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

                $recordList[] = $row;

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

        public static function getListRecord($module, array $columnList, $limit)

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

                    ->where(['isentitytype' => 1])

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

                $row['setype'] = \App\Language::translate($row['setype'], $row['setype']);

    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

            if (!\in_array('smownerid', $columnList)) {

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

            $select['smownerid'] = \App\Module::getSqlForNameInDisplayFormat('Users');

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

                ->innerJoin('vtiger_users', 'vtiger_users.id = vtiger_crmentity.smownerid')

    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 (empty($recordList)) {

    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('vtiger_tab')

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

                $limit = 200;

    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

            $moduleList = [];

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

                ->leftJoin('u_#__crmentity_label', 'u_#__crmentity_label.crmid = vtiger_crmentity.crmid')

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

                $columnList[] = 'smownerid';

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

            if ('all' == $limit) {

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

            $dataReader = (new \App\Db\Query())->select($select)->from('vtiger_crmentity')

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

                ->createCommand()->query();

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

            if (!$module) {

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

            $recordList = [];

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

                ->where(['was_read' => 0, 'vtiger_crmentity.deleted' => 0, 'setype' => $moduleList])

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

                    ->createCommand()->queryColumn();

    There are no issues that match your filters.

    Category
    Status