YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/ConfigEditor/actions/SaveAjax.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $response = new Vtiger_Response();
        $qualifiedModuleName = $request->getModule(false);
        $type = $request->has('type') ? $request->getByType('type', \App\Purifier::STANDARD) : 'Main';
Severity: Minor
Found in modules/Settings/ConfigEditor/actions/SaveAjax.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)
        {
            $response = new Vtiger_Response();
            $qualifiedModuleName = $request->getModule(false);
            $type = $request->has('type') ? $request->getByType('type', \App\Purifier::STANDARD) : 'Main';
    Severity: Minor
    Found in modules/Settings/ConfigEditor/actions/SaveAjax.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

    Missing class import via use statement (line '24', column '19').
    Open

            $response = new Vtiger_Response();

    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

    Missing class import via use statement (line '37', column '35').
    Open

                            $configFiles[$source] = new \App\ConfigFile($type, $component);

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

                $response->setError(\App\Language::translate('LBL_ERROR', $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 '\App\Language' in method 'process'.
    Open

                $response->setResult(['notify' => ['type' => 'success', 'text' => \App\Language::translate('LBL_CHANGES_SAVED')]]);

    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

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

    class Settings_ConfigEditor_SaveAjax_Action extends Settings_Vtiger_Basic_Action

    The class Settings_ConfigEditor_SaveAjax_Action is not named in CamelCase.
    Open

    class Settings_ConfigEditor_SaveAjax_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

         *

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

                    }

    Line exceeds 120 characters; contains 127 characters
    Open

                $response->setResult(['notify' => ['type' => 'success', 'text' => \App\Language::translate('LBL_CHANGES_SAVED')]]);

    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

            $type = $request->has('type') ? $request->getByType('type', \App\Purifier::STANDARD) : 'Main';

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

                foreach (array_keys($moduleModel->getEditFields()) as $fieldName) {

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

                $response->setResult(['notify' => ['type' => 'success', 'text' => \App\Language::translate('LBL_CHANGES_SAVED')]]);

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

            try {

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

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

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

                        if (!isset($configFiles[$source])) {

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

                foreach ($configFiles as $configFile) {

    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

            } catch (\Throwable $e) {

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

            $moduleModel = Settings_ConfigEditor_Module_Model::getInstance()->init($type);

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

                    $configFile->create();

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

                }

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

         * @throws \ReflectionException

    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

            $response = new Vtiger_Response();

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

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

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

                    if ($request->has($fieldName) && !$fieldModel->isEditableReadOnly()) {

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

                        $configFiles[$source]->set($fieldName, $fieldModel->getUITypeModel()->getDBValue($fieldValue));

    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

                $configFiles = [];

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

                            $configFiles[$source] = new \App\ConfigFile($type, $component);

    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

        {

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

                        $source = $fieldModel->get('source');

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

            $response->emit();

    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

         */

    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

                        [$type, $component] = strpos($source, ':') ? explode(':', $source, 2) : [$source, ''];

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

                $response->setError(\App\Language::translate('LBL_ERROR', $qualifiedModuleName));

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

    class Settings_ConfigEditor_SaveAjax_Action extends Settings_Vtiger_Basic_Action

    There are no issues that match your filters.

    Category
    Status