YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/PickListDependency/views/ConditionBuilder.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Method row has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function row(App\Request $request): void
    {
        $sourceModuleName = $request->getByType('sourceModuleName', \App\Purifier::ALNUM);
        $sourceField = $request->getByType('sourceField', \App\Purifier::ALNUM);
        $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModuleName);
Severity: Minor
Found in modules/Settings/PickListDependency/views/ConditionBuilder.php - About 1 hr to fix

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

        public function row(App\Request $request): void
        {
            $sourceModuleName = $request->getByType('sourceModuleName', \App\Purifier::ALNUM);
            $sourceField = $request->getByType('sourceField', \App\Purifier::ALNUM);
            $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModuleName);
    Severity: Minor
    Found in modules/Settings/PickListDependency/views/ConditionBuilder.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

    Avoid using static access to class '\Vtiger_Module_Model' in method 'builder'.
    Open

            $sourceModuleModel = \Vtiger_Module_Model::getInstance($sourceModuleName);

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

                } else {
                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel);
                }

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

            } else {
                $fieldInfo = $request->getForSql('fieldname', false);
                [$fieldName, $fieldModuleName, $sourceFieldName] = array_pad(explode(':', $fieldInfo), 3, false);
                if (!empty($sourceFieldName)) {
                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, Vtiger_Module_Model::getInstance($fieldModuleName));

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

            $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModuleName);

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

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, Vtiger_Module_Model::getInstance($fieldModuleName));

    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_PickListDependency_Module_Model' in method 'row'.
    Open

            $structure = Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField);

    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 'Vtiger_Field_Model' in method 'row'.
    Open

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, Vtiger_Module_Model::getInstance($fieldModuleName));

    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 'Vtiger_Field_Model' in method 'row'.
    Open

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel);

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

            } else {
                $selectedOperator = $request->getByType('operator', \App\Purifier::ALNUM);
            }

    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_PickListDependency_Module_Model' in method 'builder'.
    Open

            $viewer->assign('RECORD_STRUCTURE', Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField));

    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 function \array_key_first()
    Open

                $selectedOperator = array_key_first($operators);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RECORD_STRUCTURE_RELATED_MODULES', []);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RECORD_STRUCTURE_RELATED_MODULES', []);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('FIELD_INFO', $fieldInfo);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RECORD_STRUCTURE', Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField));

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SELECTED_OPERATOR', $selectedOperator);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SOURCE_MODULE', $sourceModuleName);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('RECORD_STRUCTURE', $structure);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('ADVANCE_CRITERIA', []);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('OPERATORS', $operators);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SOURCE_MODULE', $sourceModuleName);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SELECTED_FIELD_MODEL', $fieldModel);

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

            if ($request->isEmpty('fieldname')) {
                $fieldModel = current(current($structure));
            } else {
                $fieldInfo = $request->getForSql('fieldname', false);
                [$fieldName, $fieldModuleName, $sourceFieldName] = array_pad(explode(':', $fieldInfo), 3, false);
    modules/Vtiger/views/ConditionBuilder.php on lines 69..79

    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 118.

    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

    Avoid excessively long class names like Settings_PickListDependency_ConditionBuilder_View. Keep class name length under 40.
    Open

    class Settings_PickListDependency_ConditionBuilder_View extends Vtiger_ConditionBuilder_View
    {
        use \App\Controller\Traits\SettingsPermission;
    
        /**

    LongClassName

    Since: 2.9

    Detects when classes or interfaces are declared with excessively long names.

    Example

    class ATooLongClassNameThatHintsAtADesignProblem {
    
    }
    
    interface ATooLongInterfaceNameThatHintsAtADesignProblem {
    
    }

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

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

    class Settings_PickListDependency_ConditionBuilder_View extends Vtiger_ConditionBuilder_View

    The class Settings_PickListDependency_ConditionBuilder_View is not named in CamelCase.
    Open

    class Settings_PickListDependency_ConditionBuilder_View extends Vtiger_ConditionBuilder_View
    {
        use \App\Controller\Traits\SettingsPermission;
    
        /**

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

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

         */

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

        public function row(App\Request $request): 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

            $sourceField = $request->getByType('sourceField', \App\Purifier::ALNUM);

    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

            $viewer->assign('FIELD_INFO', $fieldInfo);

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

            $sourceModuleName = $request->getByType('sourceModuleName', \App\Purifier::ALNUM);

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

        use \App\Controller\Traits\SettingsPermission;

    Line exceeds 120 characters; contains 126 characters
    Open

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, Vtiger_Module_Model::getInstance($fieldModuleName));

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

                $selectedOperator = array_key_first($operators);

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

                $selectedOperator = $request->getByType('operator', \App\Purifier::ALNUM);

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

            $viewer->assign('ADVANCE_CRITERIA', []);

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

            }

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

         * Display the condition builder panel.

    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

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel);

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

            if ($request->isEmpty('operator', true)) {

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

            $fieldInfo = false;

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

            $viewer->assign('SELECTED_OPERATOR', $selectedOperator);

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

                [$fieldName, $fieldModuleName, $sourceFieldName] = array_pad(explode(':', $fieldInfo), 3, false);

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

            $viewer->assign('SOURCE_MODULE', $sourceModuleName);

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

                    $fieldModel = Vtiger_Field_Model::getInstance($fieldName, Vtiger_Module_Model::getInstance($fieldModuleName));

    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

            $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

        public function builder(App\Request $request): void

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

            $sourceField = $request->getByType('sourceField', \App\Purifier::ALNUM);

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

            $viewer->view('ConditionBuilder.tpl', $sourceModuleName);

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

            $structure = Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField);

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

                if (!empty($sourceFieldName)) {

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

         *

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

            $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModuleName);

    Line exceeds 120 characters; contains 126 characters
    Open

            $structure = Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField);

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

         *

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

            $sourceModuleModel = \Vtiger_Module_Model::getInstance($sourceModuleName);

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

         * Display one condition for a field.

    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('SELECTED_FIELD_MODEL', $fieldModel);

    Line exceeds 120 characters; contains 150 characters
    Open

            $viewer->assign('RECORD_STRUCTURE', Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField));

    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

         * @param App\Request $request

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

            $sourceModuleName = $request->getByType('sourceModuleName', \App\Purifier::ALNUM);

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

            if ($request->isEmpty('fieldname')) {

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

                $fieldModel = current(current($structure));

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

            }

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

            $operators = $fieldModel->getRecordOperators();

    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

            $viewer->assign('RECORD_STRUCTURE_RELATED_MODULES', []);

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

            $viewer->view('ConditionBuilderRow.tpl', $sourceModuleName);

    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('RECORD_STRUCTURE', Settings_PickListDependency_Module_Model::getConditionBuilderStructure($sourceModuleModel, $sourceField));

    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

                $fieldInfo = $request->getForSql('fieldname', false);

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

            $viewer->assign('OPERATORS', $operators);

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

            $viewer->assign('RECORD_STRUCTURE', $structure);

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

            $viewer->assign('SOURCE_MODULE', $sourceModuleName);

    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

            $viewer->assign('RECORD_STRUCTURE_RELATED_MODULES', []);

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

    class Settings_PickListDependency_ConditionBuilder_View extends Vtiger_ConditionBuilder_View

    There are no issues that match your filters.

    Category
    Status