YetiForceCompany/YetiForceCRM

View on GitHub
modules/PermissionInspector/views/UserListModal.php

Summary

Maintainability
A
2 hrs
Test Coverage
B
85%

Method process has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $this->preProcess($request);
        $moduleName = $request->getModule();
        $srcModule = $request->getByType('srcModule', 'Alnum');
Severity: Minor
Found in modules/PermissionInspector/views/UserListModal.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $this->preProcess($request);
            $moduleName = $request->getModule();
            $srcModule = $request->getByType('srcModule', 'Alnum');
    Severity: Minor
    Found in modules/PermissionInspector/views/UserListModal.php - About 55 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

    Avoid using static access to class 'ModTracker_Record_Model' in method 'process'.
    Open

                        $unreviewedChanges[$userId] = current(ModTracker_Record_Model::getUnreviewed($srcRecordId, $userId));

    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\Config' in method 'process'.
    Open

                if (App\Config::module('ModTracker', 'UNREVIEWED_COUNT')) {

    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 {
                $watchdog = \App\Privilege::isPermitted($srcModule, 'WatchingModule');
            }

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

            } else {
                $srcRecordId = 0;
            }

    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 'Vtiger_Module_Model' in method 'process'.
    Open

            $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

                $watchdog = \App\Privilege::isPermitted($srcModule, 'WatchingRecords');

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

                $watchdog = \App\Privilege::isPermitted($srcModule, 'WatchingModule');

    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 unused local variables such as '$permission'.
    Open

                    foreach ($userPermission as $userId => $permission) {

    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

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('USERS_PERMISSION', $userPermission);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('ACTIONS', $actions);

    Call to undeclared method \Vtiger_Module_Model::getUsersPermission
    Open

            $userPermission = $moduleModel->getUsersPermission();

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('UNREVIEWED_CHANGES', $unreviewedChanges);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SRC_RECORD_ID', $srcRecordId);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('WATCHDOG', $watchdog);

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

    class PermissionInspector_UserListModal_View extends Vtiger_BasicModal_View

    The class PermissionInspector_UserListModal_View is not named in CamelCase.
    Open

    class PermissionInspector_UserListModal_View extends Vtiger_BasicModal_View
    {
        /** {@inheritdoc} */
        public function getSize(App\Request $request)
        {

    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

            $moduleName = $request->getModule();

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

            return array_merge(parent::getModalScripts($request), $this->checkAndConvertJsScripts([

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

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

            return 'modal-lg c-modal--fit-lg';

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

        {

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

                $srcRecordId = $request->getInteger('srcRecord');

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

            }

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

                '~libraries/datatables.net-bs4/js/dataTables.bootstrap4.js',

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

            $this->preProcess($request);

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

            return array_merge(parent::getModalCss($request), $this->checkAndConvertCssStyles([

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

            if ($srcRecordId) {

    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

                $srcRecordId = 0;

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

                        $unreviewedChanges[$userId] = current(ModTracker_Record_Model::getUnreviewed($srcRecordId, $userId));

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

                '~libraries/datatables.net-responsive-bs4/js/responsive.bootstrap4.js'

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

        }

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

            $moduleModel->set('sourceModule', $srcModule);

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

                '~libraries/datatables.net-responsive/js/dataTables.responsive.js',

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

            if ($request->has('srcRecord')) {

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

                if (App\Config::module('ModTracker', 'UNREVIEWED_COUNT')) {

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

            $viewer->assign('WATCHDOG', $watchdog);

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

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

            $unreviewedChanges = [];

    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

            $viewer->assign('USERS_PERMISSION', $userPermission);

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

            $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

            $moduleModel->set('actions', $actions);

    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 function getModalScripts(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

        /** {@inheritdoc} */

    Line exceeds 120 characters; contains 121 characters
    Open

                        $unreviewedChanges[$userId] = current(ModTracker_Record_Model::getUnreviewed($srcRecordId, $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

            $viewer->assign('ACTIONS', $actions);

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

            $this->postProcess($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

        }

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

                '~libraries/datatables.net-responsive-bs4/css/responsive.bootstrap4.css'

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

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

                $watchdog = \App\Privilege::isPermitted($srcModule, 'WatchingModule');

    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

                '~libraries/datatables.net/js/jquery.dataTables.js',

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

                '~libraries/datatables.net-bs4/css/dataTables.bootstrap4.css',

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

            $srcModule = $request->getByType('srcModule', 'Alnum');

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

                $watchdog = \App\Privilege::isPermitted($srcModule, 'WatchingRecords');

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

            $moduleModel->set('sourceRecord', $srcRecordId);

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

            $actions = ['DetailView', 'CreateView', 'EditView', 'Delete'];

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

                    foreach ($userPermission as $userId => $permission) {

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

            $userPermission = $moduleModel->getUsersPermission();

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

            $viewer->assign('UNREVIEWED_CHANGES', $unreviewedChanges);

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

    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

            $viewer->assign('SRC_RECORD_ID', $srcRecordId);

    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->view('UserListModal.tpl', $moduleName);

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

    class PermissionInspector_UserListModal_View extends Vtiger_BasicModal_View

    There are no issues that match your filters.

    Category
    Status