YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Roles/actions/Save.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $qualifiedModuleName = $request->getModule(false);
        $recordId = $request->get('record');
        $roleName = $request->get('rolename');
Severity: Minor
Found in modules/Settings/Roles/actions/Save.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 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $qualifiedModuleName = $request->getModule(false);
        $recordId = $request->get('record');
        $roleName = $request->get('rolename');
Severity: Minor
Found in modules/Settings/Roles/actions/Save.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $qualifiedModuleName = $request->getModule(false);
            $recordId = $request->get('record');
            $roleName = $request->get('rolename');

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

                $recordModel = new Settings_Roles_Record_Model();

    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

    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 {
                $recordModel = new Settings_Roles_Record_Model();
            }

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

                $parentRole = Settings_Roles_Record_Model::getInstanceById($parentRoleId);

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

                        $profileRecordModel = Settings_Profiles_Record_Model::getInstanceById($profileId);

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

                $recordModel = Settings_Roles_Record_Model::getInstanceById($recordId);

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

            $moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);

    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

    Call to undeclared method \Settings_Vtiger_Module_Model::getDefaultUrl
    Open

            header("location: {$moduleModel->getDefaultUrl()}");
    Severity: Critical
    Found in modules/Settings/Roles/actions/Save.php by phan

    Avoid excessively long variable names like $allowassignedrecordsto. Keep variable name length under 20.
    Open

            $allowassignedrecordsto = $request->get('allowassignedrecordsto');

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

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

    class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action

    The class Settings_Roles_Save_Action is not named in CamelCase.
    Open

    class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action
    {
        /**
         * Process.
         *

    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

                    ->set('company', $request->getInteger('company'))

    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

                    $recordModel->set('rolename', $roleName);

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

            header("location: {$moduleModel->getDefaultUrl()}");

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

                if (!empty($allowassignedrecordsto)) {

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

                    foreach ($roleProfiles as $profileId) {

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

                    ->set('listrelatedrecord', $request->getInteger('listRelatedRecord'))

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

            if ($recordModel && !empty($parentRoleId)) {

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

                } // set the value of assigned records to

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

                    }

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

                    ->set('searchunpriv', $request->get('searchunpriv'))

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

                    ->set('globalsearchadv', $request->get('globalSearchAdvanced'))

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

            $roleName = $request->get('rolename');

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

            $allowassignedrecordsto = $request->get('allowassignedrecordsto');

    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

                    ->set('permissionsrelatedfield', $request->get('permissionsRelatedField'))

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

                        $profileRecordModel->recalculate();

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

                $parentRole = Settings_Roles_Record_Model::getInstanceById($parentRoleId);

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

                    ->set('previewrelatedrecord', $request->getInteger('previewRelatedRecord'))

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

                    ->set('assignedmultiowner', $request->getInteger('assignedmultiowner'))

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

                        $profileRecordModel = Settings_Profiles_Record_Model::getInstanceById($profileId);

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

        }

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

         * Process.

    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

            if (!empty($recordId)) {

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

                    ->set('clendarallorecords', $request->getInteger('clendarallorecords'))

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

                    $parentRole->addChildRole($recordModel);

    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

                    $recordModel->set('allowassignedrecordsto', $allowassignedrecordsto);

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

                if ($parentRole && !empty($roleName) && !empty($roleProfiles)) {

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

        /**

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

            $recordId = $request->get('record');

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

                if ($roleProfiles) {

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

            $qualifiedModuleName = $request->getModule(false);

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

                $recordModel = new Settings_Roles_Record_Model();

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

            $roleProfiles = $request->get('profiles');

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

                //After role updation recreating user privilege files

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

            $parentRoleId = $request->getByType('parent_roleid', 2);

    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_Roles_Record_Model::getInstanceById($recordId);

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

            }

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

                    ->set('auto_assign', $request->get('auto_assign'));

    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 = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);

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

                $recordModel->set('changeowner', $request->get('changeowner'))

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

                    ->set('editrelatedrecord', $request->get('editRelatedRecord'))

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

                    $recordModel->set('profileIds', $roleProfiles);

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

    class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action

    There are no issues that match your filters.

    Category
    Status