YetiForceCompany/YetiForceCRM

View on GitHub
modules/Users/views/MemberList.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $userModel = \App\User::getCurrentUserModel();
        $groupId = $request->getInteger('groupID');
        if ($userModel->isAdmin()) {
Severity: Minor
Found in modules/Users/views/MemberList.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 process has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $userModel = \App\User::getCurrentUserModel();
        $groupId = $request->getInteger('groupID');
        if ($userModel->isAdmin()) {
Severity: Minor
Found in modules/Users/views/MemberList.php - About 1 hr to fix

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

                throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/Users/views/MemberList.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 '\App\User' in method 'checkPermission'.
    Open

            $userModel = \App\User::getCurrentUserModel();
    Severity: Minor
    Found in modules/Users/views/MemberList.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\PrivilegeUtil' in method 'process'.
    Open

                $groups = \App\PrivilegeUtil::getMembers();
    Severity: Minor
    Found in modules/Users/views/MemberList.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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId()] = ['name' => $userModel->getName(), 'id' => $userModel->getId(), 'type' => \App\PrivilegeUtil::MEMBER_TYPE_USERS];
                $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLES] = [];
                $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES] = [];
                foreach (\App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'] as $roleId => $users) {
    Severity: Minor
    Found in modules/Users/views/MemberList.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 'Settings_Groups_Member_Model' in method 'process'.
    Open

            $groupMembers = array_flip(Settings_Groups_Member_Model::getAllByTypeForGroup($groupId));
    Severity: Minor
    Found in modules/Users/views/MemberList.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 'process'.
    Open

                    $roleName = \App\Labels::role($roleId);
    Severity: Minor
    Found in modules/Users/views/MemberList.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 'process'.
    Open

    }
    Severity: Minor
    Found in modules/Users/views/MemberList.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/views/MemberList.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 'process'.
    Open

            $userModel = \App\User::getCurrentUserModel();
    Severity: Minor
    Found in modules/Users/views/MemberList.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 'process'.
    Open

                        if (\App\User::isExists($userId)) {
    Severity: Minor
    Found in modules/Users/views/MemberList.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

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

                $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId()] = ['name' => $userModel->getName(), 'id' => $userModel->getId(), 'type' => \App\PrivilegeUtil::MEMBER_TYPE_USERS];
    Severity: Info
    Found in modules/Users/views/MemberList.php by phan

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

                        if (\App\User::isExists($userId)) {
    Severity: Critical
    Found in modules/Users/views/MemberList.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/views/MemberList.php by phan

    Class extends undeclared class \App\Controller\Modal
    Open

    class Users_MemberList_View extends \App\Controller\Modal
    Severity: Critical
    Found in modules/Users/views/MemberList.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/views/MemberList.php by phan

    Call to undeclared method \Users_MemberList_View::getViewer
    Open

            $viewer = $this->getViewer($request);
    Severity: Critical
    Found in modules/Users/views/MemberList.php by phan

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

                foreach (\App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'] as $roleId => $users) {
    Severity: Critical
    Found in modules/Users/views/MemberList.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/views/MemberList.php and 1 other location - About 1 hr to fix
    modules/Users/actions/Groups.php on lines 34..43

    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_MemberList_View extends \App\Controller\Modal

    The class Users_MemberList_View is not named in CamelCase.
    Open

    class Users_MemberList_View extends \App\Controller\Modal
    {
        /** {@inheritdoc} */
        public $successBtn = 'LBL_ADD';
    
    
    Severity: Minor
    Found in modules/Users/views/MemberList.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

    Line exceeds 120 characters; contains 121 characters
    Open

                foreach (\App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'] as $roleId => $users) {

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

                    $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLES][\App\PrivilegeUtil::MEMBER_TYPE_ROLES . ':' . $roleId] = ['name' => $roleName, 'id' => $roleId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_ROLES];

    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

                foreach (\App\User::getPrivilegesFile($userModel->getId())['subordinate_roles_users'] as $roleId => $users) {

    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

                $groups = \App\PrivilegeUtil::getMembers();

    Line exceeds 120 characters; contains 240 characters
    Open

                $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId()] = ['name' => $userModel->getName(), 'id' => $userModel->getId(), 'type' => \App\PrivilegeUtil::MEMBER_TYPE_USERS];

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

                $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES] = [];

    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

        public function checkPermission(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

        public $modalIcon = 'fas fa-plus';

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

        /** {@inheritdoc} */

    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

            } else {

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

        public $successBtn = 'LBL_ADD';

    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

        {

    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

            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

            if ($userModel->isAdmin()) {

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

                $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLES] = [];

    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

        /** {@inheritdoc} */

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

                $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId()] = ['name' => $userModel->getName(), 'id' => $userModel->getId(), 'type' => \App\PrivilegeUtil::MEMBER_TYPE_USERS];

    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

                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

        /** {@inheritdoc} */

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

                    $roleName = \App\Labels::role($roleId);

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

        public function process(App\Request $request)

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

                        if (\App\User::isExists($userId)) {

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

                }

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

                $members = array_diff_key($members, $groupMembers);

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

        protected $pageTitle = 'LBL_GROUP_MEMBERS_ADD_VIEW';

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

                    foreach ($users as $userId => $userName) {

    Line exceeds 120 characters; contains 208 characters
    Open

                    $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLES][\App\PrivilegeUtil::MEMBER_TYPE_ROLES . ':' . $roleId] = ['name' => $roleName, 'id' => $roleId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_ROLES];

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

            }

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

            $viewer->assign('GROUPS', $groups);

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

            $viewer->view('MemberList.tpl', $request->getModule());

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

                    }

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

            $viewer = $this->getViewer($request);

    Line exceeds 120 characters; contains 256 characters
    Open

                    $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES][\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES . ':' . $roleId] = ['name' => $roleName, 'id' => $roleId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES];

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

                    $groups[\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES][\App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES . ':' . $roleId] = ['name' => $roleName, 'id' => $roleId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES];

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

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

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

                            $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userId] = ['name' => $userName, 'id' => $userId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_USERS];

    Line exceeds 120 characters; contains 216 characters
    Open

                            $groups[\App\PrivilegeUtil::MEMBER_TYPE_USERS][\App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userId] = ['name' => $userName, 'id' => $userId, 'type' => \App\PrivilegeUtil::MEMBER_TYPE_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

            $groupMembers[\App\PrivilegeUtil::MEMBER_TYPE_GROUPS . ":{$groupId}"] = 0;

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

            foreach ($groups as &$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

            $viewer->assign('GROUP_ID', $groupId);

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

            }

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

    class Users_MemberList_View extends \App\Controller\Modal

    There are no issues that match your filters.

    Category
    Status