YetiForceCompany/YetiForceCRM

View on GitHub
modules/Users/actions/Groups.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    private function isMemberEditable(string $member): bool
    {
        $userModel = \App\User::getCurrentUserModel();
        [$type, $id] = explode(':', $member);
        if (!$userModel->isAdmin() && null === $this->subordinates) {
Severity: Minor
Found in modules/Users/actions/Groups.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

Method getData has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getData(App\Request $request)
    {
        $moduleName = $request->getModule();
        $groupId = $request->getInteger('groupID');
        $groupMembers = Settings_Groups_Member_Model::getAllByTypeForGroup($groupId);
Severity: Minor
Found in modules/Users/actions/Groups.php - About 1 hr to fix

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

        public function getData(App\Request $request)
        {
            $moduleName = $request->getModule();
            $groupId = $request->getInteger('groupID');
            $groupMembers = Settings_Groups_Member_Model::getAllByTypeForGroup($groupId);
    Severity: Minor
    Found in modules/Users/actions/Groups.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

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

        private function isMemberEditable(string $member): bool
        {
            $userModel = \App\User::getCurrentUserModel();
            [$type, $id] = explode(':', $member);
            if (!$userModel->isAdmin() && null === $this->subordinates) {
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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

    Missing class import via use statement (line '179', column '19').
    Open

            $response = new \Vtiger_Response();
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '41', column '14').
    Open

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '131', column '14').
    Open

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '143', column '19').
    Open

            $response = new \Vtiger_Response();
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '164', column '15').
    Open

                    throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class 'Settings_Groups_Member_Model' in method 'getData'.
    Open

            $groupMembers = Settings_Groups_Member_Model::getAllByTypeForGroup($groupId);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\Settings_Groups_Record_Model' in method 'removeMember'.
    Open

            $recordModel = \Settings_Groups_Record_Model::getInstance($groupId);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Json' in method 'getData'.
    Open

            echo \App\Json::encode($result);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\User' in method 'getData'.
    Open

                if (\App\PrivilegeUtil::MEMBER_TYPE_USERS === $type && !\App\User::isExists($id)) {
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

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

                } else {
                    $data[] = '';
                }
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

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

                    $data[] = '<button type="button" class="btn btn-danger btn-sm js-member-delete" data-id="' . $member . '" title="' . \App\Language::translate('LBL_DELETE') . '" data-url="' . "index.php?&module={$moduleName}&action=Groups&mode=removeMember&groupID={$groupId}&member={$member}" . '"><span class="fas fa-trash-alt"></span></button>';
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Privilege' in method 'checkPermission'.
    Open

            if (!$groupId || !\in_array($groupId, $userModel->get('leader')) || !\App\Privilege::isPermitted($moduleName, 'LeaderCanManageGroupMembership')) {
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\User' in method 'isMemberEditable'.
    Open

            $userModel = \App\User::getCurrentUserModel();
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Language' in method 'addMembers'.
    Open

                $result = ['success' => false, 'message' => \App\Language::translate($errorLabel, 'Settings:Groups')];
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\User' in method 'checkPermission'.
    Open

            $userModel = \App\User::getCurrentUserModel();
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid assigning values to variables in if clauses and the like (line '137', column '42').
    Open

        public function removeMember(App\Request $request)
        {
            $groupId = $request->getInteger('groupID');
            $member = $request->getByType('member', \App\Purifier::TEXT);
            if (!$this->isMemberEditable($member)) {
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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\User' in method 'isMemberEditable'.
    Open

    }
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\Settings_Groups_Record_Model' in method 'addMembers'.
    Open

            $recordModel = \Settings_Groups_Record_Model::getInstance($groupId);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Labels' in method 'getData'.
    Open

                $label = \App\Labels::member($member);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid assigning values to variables in if clauses and the like (line '102', column '11').
    Open

        private function isMemberEditable(string $member): bool
        {
            $userModel = \App\User::getCurrentUserModel();
            [$type, $id] = explode(':', $member);
            if (!$userModel->isAdmin() && null === $this->subordinates) {
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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 assigning values to variables in if clauses and the like (line '173', column '7').
    Open

        public function addMembers(App\Request $request)
        {
            $groupId = $request->getInteger('groupID');
            $recordModel = \Settings_Groups_Record_Model::getInstance($groupId);
            $fieldModel = $recordModel->getFieldInstanceByName('members');
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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

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

            $groupId = $request->getInteger('groupID', 0);
    Severity: Critical
    Found in modules/Users/actions/Groups.php by sonar-php

    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 "members" 6 times.
    Open

            $memberModel = $recordModel->getFieldInstanceByName('members');
    Severity: Critical
    Found in modules/Users/actions/Groups.php by sonar-php

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

            $response->setResult(['success' => true]);
    Severity: Critical
    Found in modules/Users/actions/Groups.php by sonar-php

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

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Critical
    Found in modules/Users/actions/Groups.php by sonar-php

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

            $userModel = \App\User::getCurrentUserModel();
    Severity: Critical
    Found in modules/Users/actions/Groups.php by phan

    Argument 1 (value) is array but \Vtiger_Field_Model::getDBValue() takes \type defined at /code/modules/Vtiger/models/Field.php:1357
    Open

            $recordModel->set('members', $fieldModel->getDBValue($members));
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phan

    Call to method getCurrentUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

            $userModel = \App\User::getCurrentUserModel();
    Severity: Critical
    Found in modules/Users/actions/Groups.php by phan

    Call to method getPrivilegesFile from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                $this->subordinates = \App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'];
    Severity: Critical
    Found in modules/Users/actions/Groups.php by phan

    Call to method isExists from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                if (\App\PrivilegeUtil::MEMBER_TYPE_USERS === $type && !\App\User::isExists($id)) {
    Severity: Critical
    Found in modules/Users/actions/Groups.php by phan

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        public function checkPermission(App\Request $request)
        {
            $moduleName = $request->getModule();
            $groupId = $request->getInteger('groupID', 0);
            $userModel = \App\User::getCurrentUserModel();
    Severity: Major
    Found in modules/Users/actions/Groups.php and 1 other location - About 1 hr to fix
    modules/Users/views/MemberList.php on lines 27..36

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 106.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class Users_Groups_Action extends \App\Controller\Action

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

                [$type, $id] = explode(':', $member);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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 $id. Configured minimum length is 3.
    Open

            [$type, $id] = explode(':', $member);
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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

    The class Users_Groups_Action is not named in CamelCase.
    Open

    class Users_Groups_Action extends \App\Controller\Action
    {
        use \App\Controller\ExposeMethod;
        use \App\Controller\Traits\SettingsPermission;
    
    
    Severity: Minor
    Found in modules/Users/actions/Groups.php by phpmd

    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

        use \App\Controller\Traits\SettingsPermission;

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

        public function __construct()

    Line exceeds 120 characters; contains 154 characters
    Open

            if (!$groupId || !\in_array($groupId, $userModel->get('leader')) || !\App\Privilege::isPermitted($moduleName, 'LeaderCanManageGroupMembership')) {

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

         * Gets data for DataTable element.

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

                $label = \App\Labels::member($member);

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

                if ($count > 1 && $this->isMemberEditable($member)) {

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

            $result = [

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

            if (!$userModel->isAdmin() && null === $this->subordinates) {

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

            if (!$editable) {

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

         */

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

                        $editable = isset($this->subordinates[$id]);

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

        private $subordinates;

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

         * @param App\Request $request

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

                }

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

            $userModel = \App\User::getCurrentUserModel();

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

        use \App\Controller\ExposeMethod;

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

        public function checkPermission(App\Request $request)

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

            $groupId = $request->getInteger('groupID', 0);

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

            $groupId = $request->getInteger('groupID');

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

            [$type, $id] = explode(':', $member);

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

                                break;

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

                    case \App\PrivilegeUtil::MEMBER_TYPE_ROLES:

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

            $this->exposeMethod('getData');

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

            foreach ($groupMembers as $member) {

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

                    $data[] = '<button type="button" class="btn btn-danger btn-sm js-member-delete" data-id="' . $member . '" title="' . \App\Language::translate('LBL_DELETE') . '" data-url="' . "index.php?&module={$moduleName}&action=Groups&mode=removeMember&groupID={$groupId}&member={$member}" . '"><span class="fas fa-trash-alt"></span></button>';

    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

                $rows[] = $data;

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

                'aaData' => $rows

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

                    default:

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

            if (!$groupId || !\in_array($groupId, $userModel->get('leader')) || !\App\Privilege::isPermitted($moduleName, 'LeaderCanManageGroupMembership')) {

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

        /**

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

                    $label = "<del>{$label}</del>";

    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

         * Remove member from group.

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

                $data = [$label];

    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->subordinates = \App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'];

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

                switch ($type) {

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

        /** {@inheritdoc} */

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

            $this->exposeMethod('removeMember');

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

        }

    Line exceeds 120 characters; contains 347 characters
    Open

                    $data[] = '<button type="button" class="btn btn-danger btn-sm js-member-delete" data-id="' . $member . '" title="' . \App\Language::translate('LBL_DELETE') . '" data-url="' . "index.php?&module={$moduleName}&action=Groups&mode=removeMember&groupID={$groupId}&member={$member}" . '"><span class="fas fa-trash-alt"></span></button>';

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

                        foreach ($this->subordinates as $users) {

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

                    case \App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES:

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

                        break;

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

            return $editable;

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

            parent::__construct();

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

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);

    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

                    $data[] = '';

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

                'draw' => $request->getInteger('draw'),

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

            header('content-type: text/json; charset=UTF-8');

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

         * Check if given member is editable for current user.

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

                        break;

    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 getData(App\Request $request)

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

            $moduleName = $request->getModule();

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

                if (\App\PrivilegeUtil::MEMBER_TYPE_USERS === $type && !\App\User::isExists($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

         * @param string $member

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

        private function isMemberEditable(string $member): bool

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

            $editable = $userModel->isAdmin() || $id == $userModel->getId();

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

                        }

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

                        break;

    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

            $groupMembers = Settings_Groups_Member_Model::getAllByTypeForGroup($groupId);

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

            $count = \count($groupMembers);

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

            echo \App\Json::encode($result);

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

        /** {@inheritdoc} */

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

            $rows = [];

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

         */

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

                    case \App\PrivilegeUtil::MEMBER_TYPE_USERS:

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

                            if ($editable = isset($users[$id]) || $id === $userModel->getId()) {

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

        /** @var array Subordinate roles/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

         * @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

                }

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

                'iTotalDisplayRecords' => \count($groupMembers),

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

            $this->exposeMethod('addMembers');

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

        {

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

            $moduleName = $request->getModule();

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

            $userModel = \App\User::getCurrentUserModel();

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

                [$type, $id] = explode(':', $member);

    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

            $member = $request->getByType('member', \App\Purifier::TEXT);

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

            $response->setResult(['success' => 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

            $fieldModel = $recordModel->getFieldInstanceByName('members');

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

            $members = array_unique(array_merge($currentMembers, $newMembers));

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

            if (\count($members) > 1 && false !== ($key = array_search($member, $members))) {

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

         * @param App\Request $request

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

            $newMembers = $request->getByType($fieldModel->getName(), $fieldModel->get('purifyType'));

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

            $recordModel->set('members', $fieldModel->getDBValue($members));

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

                $result = ['success' => false, 'message' => \App\Language::translate($errorLabel, 'Settings:Groups')];

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

         */

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

            $recordModel = \Settings_Groups_Record_Model::getInstance($groupId);

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

            $members = $memberModel->getEditViewDisplayValue($recordModel->get('members') ?? '');

    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

                if (!$this->isMemberEditable($member)) {

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

         * @param App\Request $request

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

        /**

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

            $fieldModel->getUITypeModel()->validate($newMembers, 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

         * @return void

    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 (!$this->isMemberEditable($member)) {

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

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);

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

                unset($members[$key]);

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

                $recordModel->save();

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

            }

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

            $response = new \Vtiger_Response();

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

            if ($errorLabel = $recordModel->validate()) {

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

            $groupId = $request->getInteger('groupID');

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

                $recordModel->set('members', $memberModel->getDBValue($members));

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

            $groupId = $request->getInteger('groupID');

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

            $currentMembers = $fieldModel->getEditViewDisplayValue($recordModel->get('members') ?? '');

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

            $response->setResult($result);

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

            $response->emit();

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

            $result = ['success' => true];

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

            $response = new \Vtiger_Response();

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

        public function removeMember(App\Request $request)

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

                    throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);

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

                $recordModel->save();

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

         *

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

            $memberModel = $recordModel->getFieldInstanceByName('members');

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

            foreach ($newMembers as $member) {

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

            $response->emit();

    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

         */

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

         * Add members to group.

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

        public function addMembers(App\Request $request)

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

            $recordModel = \Settings_Groups_Record_Model::getInstance($groupId);

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

            } elseif ($recordModel->getPreviousValue()) {

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

    class Users_Groups_Action extends \App\Controller\Action

    There are no issues that match your filters.

    Category
    Status