YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/QuickCreateEditor/views/Index.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

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

    public function showFieldLayout(App\Request $request)
    {
        $sourceModule = $request->getByType('sourceModule', 2);
        $menuModelsList = \App\Module::getQuickCreateModules();

Severity: Minor
Found in modules/Settings/QuickCreateEditor/views/Index.php - About 1 hr to fix

    Function showFieldLayout has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function showFieldLayout(App\Request $request)
        {
            $sourceModule = $request->getByType('sourceModule', 2);
            $menuModelsList = \App\Module::getQuickCreateModules();
    
    
    Severity: Minor
    Found in modules/Settings/QuickCreateEditor/views/Index.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

    Avoid using static access to class '\App\Module' in method 'showFieldLayout'.
    Open

            $menuModelsList = \App\Module::getQuickCreateModules();

    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_Record_Model' in method 'showFieldLayout'.
    Open

            $recordModel = Vtiger_Record_Model::getCleanInstance($sourceModule);

    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 {
                $this->showFieldLayout($request);
            }

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

                    } else {
                        unset($blockModels[$blockKey]);
                    }

    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 to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('LAYOUT', $layout);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('SELECTED_MODULE_MODEL', $selectedModuleModel);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SUPPORTED_MODULES', $menuModelsList);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SELECTED_MODULE_NAME', $sourceModule);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('BLOCKS', $blockModels);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

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

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

    class Settings_QuickCreateEditor_Index_View extends Settings_Vtiger_Index_View

    The class Settings_QuickCreateEditor_Index_View is not named in CamelCase.
    Open

    class Settings_QuickCreateEditor_Index_View extends Settings_Vtiger_Index_View
    {
        use \App\Controller\ExposeMethod;
    
        public function __construct()

    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

                $this->showFieldLayout($request);

    Line exceeds 120 characters; contains 181 characters
    Open

            $quickCreateFields = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_QUICKCREATE)->getStructure();

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

            $mode = $request->getMode();

    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

                $blockIdFieldMap = [];

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

                    if (isset($blockIdFieldMap[$blockModel->get('id')])) {

    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

                $this->invokeExposedMethod($mode, $request);

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

            if (empty($sourceModule)) {

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

            $recordModel = Vtiger_Record_Model::getCleanInstance($sourceModule);

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

                $blockModels = $selectedModuleModel->getBlocks();

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

                foreach ($blockModels as $blockKey => $blockModel) {

    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

            if ($this->isMethodExposed($mode)) {

    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

            } else {

    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

        public function __construct()

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

                $selectedModuleModel = Settings_LayoutEditor_Module_Model::getInstance('Settings:LayoutEditor')->setSourceModule($sourceModule);

    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

                    } else {

    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

                foreach ($quickCreateFields as $fieldModel) {

    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

                        $fieldModelList = $blockIdFieldMap[$blockModel->get('id')];

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

            $viewer->assign('SELECTED_MODULE_NAME', $sourceModule);

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

            parent::__construct();

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

            $menuModelsList = \App\Module::getQuickCreateModules();

    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

                    $blockIdFieldMap[$fieldModel->getBlockId()][$fieldModel->getName()] = $fieldModel;

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

        }

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

            $this->exposeMethod('showFieldLayout');

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

        public function showFieldLayout(App\Request $request)

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

            if ('blocks' === $layout) {

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

            $viewer->view('Index.tpl', $request->getModule(false));

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

        {

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

                $firstElement = reset($menuModelsList);

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

            $layout = $recordModel->getModule()->getLayoutTypeForQuickCreate();

    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('SUPPORTED_MODULES', $menuModelsList);

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

                $viewer->assign('BLOCKS', $blockModels);

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

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

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

        /**

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

         * View.

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

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

    Line exceeds 120 characters; contains 140 characters
    Open

                $selectedModuleModel = Settings_LayoutEditor_Module_Model::getInstance('Settings:LayoutEditor')->setSourceModule($sourceModule);

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

        use \App\Controller\ExposeMethod;

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

                $sourceModule = $firstElement->get('name');

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

                        unset($blockModels[$blockKey]);

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

            $viewer->assign('LAYOUT', $layout);

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

                $viewer->assign('SELECTED_MODULE_MODEL', $selectedModuleModel);

    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

         * @param \App\Request $request

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

            $quickCreateFields = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_QUICKCREATE)->getStructure();

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

                        $blockModel->setFields($fieldModelList);

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

    class Settings_QuickCreateEditor_Index_View extends Settings_Vtiger_Index_View

    There are no issues that match your filters.

    Category
    Status