YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $qualifiedModuleName = $request->getModule(false);
        if (!$request->isEmpty('record', true)) {
            $recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
Severity: Minor
Found in modules/Settings/TreesManager/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 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $qualifiedModuleName = $request->getModule(false);
        if (!$request->isEmpty('record', true)) {
            $recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
Severity: Minor
Found in modules/Settings/TreesManager/actions/Save.php - About 1 hr to fix

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

                $recordModel = Settings_TreesManager_Record_Model::getCleanInstance($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

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

                $recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));

    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 {
                $recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);
            }

    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

    Call with 1 arg(s) to \Settings_TreesManager_Record_Model::getCleanInstance() which only takes 0 arg(s) defined at /code/modules/Settings/TreesManager/models/Record.php:407
    Open

                $recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);

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

    class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action

    The class Settings_TreesManager_Save_Action is not named in CamelCase.
    Open

    class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action
    {
        /**
         * Save tree.
         *

    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

                if ($request->has($fieldName)) {

    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

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

            header('location: ' . $recordModel->getModule()->getListViewUrl());

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

                $recordModel->set('replace', $request->getMultiDimensionArray('replace', [['old' => ['Integer'], ['new' => ['Integer']]]]));

    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

                    $fieldModel = $recordModel->getFieldInstanceByName($fieldName);

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

                            $fieldUITypeModel->validate($value, true);

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

         * Save tree.

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

                    if ($fieldModel->isEditableReadOnly()) {

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

                        continue;

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

                    switch ($fieldName) {

    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 'tree':

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

            foreach ($fields as $fieldName) {

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

                            $value = $recordModel->parseTreeDataForSave($tree);

    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

                            $value = $request->getArray($fieldName, \App\Purifier::INTEGER);

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

                            $tree = $request->getArray('tree', 'Text');

    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

                            break;

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

                    $recordModel->set($fieldName, $value);

    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 (!$request->isEmpty('record', true)) {

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

            $fields['tree'] = 'tree';

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

                            $value = $request->getByType($fieldName, $fieldModel->get('purifyType'));

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

            }

    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

                            $fieldUITypeModel = $fieldModel->getUITypeModel();

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

        }

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

                            $value = array_intersect($value, array_keys($fieldModel->getPicklistValues()));

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

                $recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);

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

                            $value = $fieldModel->getDBValue($value);

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

         */

    Line exceeds 120 characters; contains 136 characters
    Open

                $recordModel->set('replace', $request->getMultiDimensionArray('replace', [['old' => ['Integer'], ['new' => ['Integer']]]]));

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

                        case 'share':

    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

            $fields = $recordModel->editFields;

    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

                    }

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

                $recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));

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

                    }

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

    class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action

    There are no issues that match your filters.

    Category
    Status