YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Users/models/Module.php

Summary

Maintainability
C
1 day
Test Coverage
F
54%

Function saveLocks has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    public function saveLocks($data)
    {
        $oldValues = $this->getLocks();
        $map = $toSave = [];
        if (!empty($data)) {
Severity: Minor
Found in modules/Settings/Users/models/Module.php - About 5 hrs 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

Method saveLocks has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function saveLocks($data)
    {
        $oldValues = $this->getLocks();
        $map = $toSave = [];
        if (!empty($data)) {
Severity: Major
Found in modules/Settings/Users/models/Module.php - About 2 hrs to fix

    Function saveSwitchUsers has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public function saveSwitchUsers($data): void
        {
            $switchUsers = $switchUsersRaw = [];
            if (!empty($data) && \count($data)) {
                foreach ($data as $row) {
    Severity: Minor
    Found in modules/Settings/Users/models/Module.php - About 1 hr 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 saveLocks() has an NPath complexity of 576. The configured NPath complexity threshold is 200.
    Open

        public function saveLocks($data)
        {
            $oldValues = $this->getLocks();
            $map = $toSave = [];
            if (!empty($data)) {

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

    Source https://phpmd.org/rules/codesize.html#npathcomplexity

    The method saveLocks() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
    Open

        public function saveLocks($data)
        {
            $oldValues = $this->getLocks();
            $map = $toSave = [];
            if (!empty($data)) {

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 37 to the 15 allowed.
    Open

        public function saveLocks($data)

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Avoid using undefined variables such as '$switchUsersRaw' which will lead to PHP notices.
    Open

            return $switchUsersRaw ?? [];

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$prev' which will lead to PHP notices.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$post' which will lead to PHP notices.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$locksRaw' which will lead to PHP notices.
    Open

            return $locksRaw;

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$prev' which will lead to PHP notices.
    Open

                        $prev[$name] = implode(',', $oldValues[$id]);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$prev' which will lead to PHP notices.
    Open

                        $prev[$name] = '';

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$post' which will lead to PHP notices.
    Open

                    $post[$name] = implode(',', $newValues[$id]);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$post' which will lead to PHP notices.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$post' which will lead to PHP notices.
    Open

                        $post[$name] = '';

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$post' which will lead to PHP notices.
    Open

                        $post[$name] = implode(',', $newValues[$id]);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$prev' which will lead to PHP notices.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$prev' which will lead to PHP notices.
    Open

                    $prev[$name] = implode(',', $oldValues[$id]);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Missing class import via use statement (line '35', column '17').
    Open

            $query = (new \App\Db\Query())->from('yetiforce_auth')->where(['type' => $type]);

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

                $return = (new \App\Db\Query())->select(['userid'])

    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\Utils' in method 'saveSwitchUsers'.
    Open

            $content = '$switchUsersRaw = ' . \App\Utils::varExport($switchUsersRaw) . ';' . PHP_EOL .

    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\Utils' in method 'saveSwitchUsers'.
    Open

            \App\Utils::saveToFile(ROOT_DIRECTORY . '/user_privileges/switchUsers.php', $content, 'File generated from the panel');

    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\Utils' in method 'saveSwitchUsers'.
    Open

                '$switchUsers = ' . \App\Utils::varExport($switchUsers) . ';';

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

            } else {
                $return = [(int) $data];
            }

    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

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

                    } else {
                        $name = Settings_Roles_Record_Model::getInstanceById($id);
                    }

    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\Utils' in method 'saveLocks'.
    Open

                '$locks = ' . \App\Utils::varExport($map) . ';';

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

                    } else {
                        $toSave[$row['user']] = $row['locks'];
                    }

    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\Utils' in method 'saveLocks'.
    Open

            \App\Utils::saveToFile('user_privileges/locks.php', $content);

    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 'Users_Record_Model' in method 'saveLocks'.
    Open

                        $name = Users_Record_Model::getInstanceById($id, '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 saveLocks uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $name = Settings_Roles_Record_Model::getInstanceById($id);
                    }

    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

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

                    } else {
                        $prev[$name] = '';
                    }

    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 'Settings_Roles_Record_Model' in method 'saveLocks'.
    Open

                        $name = Settings_Roles_Record_Model::getInstanceById($id);

    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 'Settings_Vtiger_Tracker_Model' in method 'saveLocks'.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    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 'Settings_Roles_Record_Model' in method 'saveLocks'.
    Open

                        $name = Settings_Roles_Record_Model::getInstanceById($id);

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

                    } else {
                        $post[$name] = '';
                    }

    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\Utils' in method 'saveLocks'.
    Open

            $content = '$locksRaw = ' . \App\Utils::varExport($toSave) . ';' . PHP_EOL .

    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 'Settings_Vtiger_Tracker_Model' in method 'saveLocks'.
    Open

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

    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 'vtlib\Functions' in method 'saveLocks'.
    Open

            $difference = vtlib\Functions::arrayDiffAssocRecursive($newValues, $oldValues);

    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 'vtlib\Functions' in method 'saveLocks'.
    Open

            $difference = vtlib\Functions::arrayDiffAssocRecursive($oldValues, $newValues);

    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 'Settings_Vtiger_Tracker_Model' in method 'saveLocks'.
    Open

                Settings_Vtiger_Tracker_Model::changeType('delete');

    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 'Users_Record_Model' in method 'saveLocks'.
    Open

                        $name = Users_Record_Model::getInstanceById($id, '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

    Define a constant instead of duplicating this literal "access" 3 times.
    Open

                    $switchUsersRaw[$row['user']] = $row['access'];

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

                $config[$row['param']] = $row['value'];

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

                    if (empty($row['locks'])) {

    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.

    Avoid unused parameters such as '$name'.
    Open

        public static function getInstance($name = 'Settings:Vtiger')

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused local variables such as '$switchUsersRaw'.
    Open

            return $switchUsersRaw ?? [];

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Avoid unused local variables such as '$locksRaw'.
    Open

            return $locksRaw;

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Variable $post was undeclared, but array fields are being added to it.
    Open

                    $post[$name] = implode(',', $newValues[$id]);

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

            $query = (new \App\Db\Query())->from('yetiforce_auth')->where(['type' => $type]);
    Severity: Critical
    Found in modules/Settings/Users/models/Module.php by phan

    Return type of getInstance() is undeclared type \self
    Open

        public static function getInstance($name = 'Settings:Vtiger')

    Variable $prev was undeclared, but array fields are being added to it.
    Open

                        $prev[$name] = implode(',', $oldValues[$id]);

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

                $return = (new \App\Db\Query())->select(['userid'])
    Severity: Critical
    Found in modules/Settings/Users/models/Module.php by phan

    Variable $locksRaw is undeclared
    Open

            return $locksRaw;

    Variable $switchUsersRaw is undeclared
    Open

            return $switchUsersRaw ?? [];

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

            App\Db::getInstance()->createCommand()
    Severity: Critical
    Found in modules/Settings/Users/models/Module.php by phan

    Variable $prev was undeclared, but array fields are being added to it.
    Open

                        $prev[$name] = '';

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

    class Settings_Users_Module_Model extends Settings_Vtiger_Module_Model

    The class Settings_Users_Module_Model is not named in CamelCase.
    Open

    class Settings_Users_Module_Model extends Settings_Vtiger_Module_Model
    {
        /**
         * Get instance.
         *

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    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 getConfig($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

         * @return bool

    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

                    ->where(['and', ['roleid' => $data], ['<>', 'status', 'Inactive']])

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

         * Set config type, parameter value pair.

    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

            self::$usersID[$data] = $return;

    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

         * @return array

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

         */

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

            $config = [];

    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 function getUserID($data): array

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

        {

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

                        foreach ($row['access'] as $access) {

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

                            $accessList = array_merge($accessList, $this->getUserID($access));

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

                '$switchUsers = ' . \App\Utils::varExport($switchUsers) . ';';

    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

         * @var array

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

            if ('H' === substr($data, 0, 1)) {

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

                $return = [(int) $data];

    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

                    $switchUsersRaw[$row['user']] = $row['access'];

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

         * Returns the list of users to switch.

    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

            $dataReader = $query->createCommand()->query();

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

            return $config;

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

                    if (\count($row['access'])) {

    Line exceeds 120 characters; contains 127 characters
    Open

            \App\Utils::saveToFile(ROOT_DIRECTORY . '/user_privileges/switchUsers.php', $content, 'File generated from the panel');

    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 (\array_key_exists($data, self::$usersID)) {

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

         */

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

            require ROOT_DIRECTORY . '/user_privileges/switchUsers.php';

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

                    ->column();

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

         * Get config.

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

            $query = (new \App\Db\Query())->from('yetiforce_auth')->where(['type' => $type]);

    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

         *

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

            if (\is_array($value)) {

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

                    $accessList = [];

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

        public function getSwitchUsers(): array

    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

        public static function getInstance($name = 'Settings:Vtiger')

    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

        }

    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

         * @return \self

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

            $value = $param['val'];

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

         * Save configuration about switching between users.

    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

        public function saveSwitchUsers($data): void

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

                    foreach ($this->getUserID($row['user']) as $user) {

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

         * @return array

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

         * Users id.

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

                return self::$usersID[$data];

    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

        /**

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

                ->update('yetiforce_auth', ['value' => $value], ['type' => $param['type'], 'param' => $param['param']])

    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 $switchUsersRaw ?? [];

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

                    ->innerJoin('vtiger_users', 'vtiger_users.id = vtiger_user2role.userid')

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

                $value = implode(',', $value);

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

         * @param array $data

    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

            $content = '$switchUsersRaw = ' . \App\Utils::varExport($switchUsersRaw) . ';' . PHP_EOL .

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

        /**

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

         * Get user id.

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

         * @return int[]

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

         * Get instance.

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

         * @param string $name

    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

                $config[$row['param']] = $row['value'];

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

            if (!empty($data) && \count($data)) {

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

                        $switchUsers[$user] = array_merge($switchUsers[$user] ?? [], $accessList);

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

            \App\Utils::saveToFile(ROOT_DIRECTORY . '/user_privileges/switchUsers.php', $content, 'File generated from the panel');

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

         * @param string $data

    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 new self();

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

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

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

            $switchUsers = $switchUsersRaw = [];

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

                foreach ($data as $row) {

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

        public static $usersID = [];

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

                $return = (new \App\Db\Query())->select(['userid'])

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

            return $return;

    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 string[]

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

        {

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

                'drag' => 'LBL_LOCK_DRAG',

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

                    $post[$name] = implode(',', $newValues[$id]);

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

            $difference = vtlib\Functions::arrayDiffAssocRecursive($oldValues, $newValues);

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

            if (!empty($difference)) {

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

                    }

    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

         * @param array $param

    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 setConfig($param)

    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_user2role')

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

                'paste' => 'LBL_LOCK_PASTE',

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

         * @param array $data

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

            $map = $toSave = [];

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

                    if (\array_key_exists($row['user'], $toSave)) {

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

                        $toSave[$row['user']] = $row['locks'];

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

                    }

    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

                }

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

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

                    if (false === strpos($id, 'H')) {

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

                    $prev[$name] = implode(',', $oldValues[$id]);

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

                    if (!empty($newValues[$id])) {

    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

                foreach ($toSave as $user => &$locks) {

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

                'cut' => 'LBL_LOCK_CUT',

    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 saveLocks($data)

    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

                        $name = Settings_Roles_Record_Model::getInstanceById($id);

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

                    }

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

                foreach ($difference as $id => $locks) {

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

                        $name = Users_Record_Model::getInstanceById($id, 'Users');

    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 getLocksTypes()

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

                    }

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

                    $locks = array_unique($locks);

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

            $difference = vtlib\Functions::arrayDiffAssocRecursive($newValues, $oldValues);

    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

                'selectstart' => 'LBL_LOCK_SELECT_TEXT',

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

        }

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

                        $toSave[$row['user']] = array_merge($toSave[$row['user']], $row['locks']);

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

                        $prev[$name] = implode(',', $oldValues[$id]);

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

         * Function to get locks.

    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

        {

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

                foreach ($data as $row) {

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

                    if (empty($row['locks'])) {

    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

            \App\Utils::saveToFile('user_privileges/locks.php', $content);

    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

                    if (false === strpos($id, 'H')) {

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

        }

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

            include 'user_privileges/locks.php';

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

                Settings_Vtiger_Tracker_Model::changeType('delete');

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

                    }

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

                        $post[$name] = '';

    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

         * Function to save locks for users.

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

            $oldValues = $this->getLocks();

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

            $newValues = $this->getLocks();

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

                foreach ($difference as $id => $locks) {

    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

                        $post[$name] = implode(',', $newValues[$id]);

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

            if (!empty($data)) {

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

                        $map[$userID] = array_merge($map[$userID] ?? [], $locks);

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

            $content = '$locksRaw = ' . \App\Utils::varExport($toSave) . ';' . PHP_EOL .

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

                '$locks = ' . \App\Utils::varExport($map) . ';';

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

         * Return type of locks.

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

                    foreach ($this->getUserID($user) as $userID) {

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

                        $name = Users_Record_Model::getInstanceById($id, 'Users');

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

                    if (!empty($oldValues[$id])) {

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

                        $prev[$name] = '';

    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 array

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

        public function getLocks()

    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

                    } else {

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

            return $locksRaw;

    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

                'copy' => 'LBL_LOCK_COPY',

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

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

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

            }

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

                    $name = $name->getName();

    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

                'contextmenu' => 'LBL_LOCK_RIGHT_MENU',

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

                    $name = $name->getName();

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

                        $name = Settings_Roles_Record_Model::getInstanceById($id);

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

                    Settings_Vtiger_Tracker_Model::addDetail($prev, $post);

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

    class Settings_Users_Module_Model extends Settings_Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status