YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/CustomView/views/SortOrderModal.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Function getStructure has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    public function getStructure(string $moduleName = null, ?string $referenceFieldName = null): array
    {
        $structures = [];
        foreach (\Vtiger_Module_Model::getInstance($moduleName)->getFields() as $fieldModel) {
            if ($fieldModel->isViewable() && $fieldModel->isListviewSortable()) {
Severity: Minor
Found in modules/Settings/CustomView/views/SortOrderModal.php - About 3 hrs 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

Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.
Open

    public function getStructure(string $moduleName = null, ?string $referenceFieldName = null): array

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

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

        $customView = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

        $sourceModuleModel = \Vtiger_Module_Model::getInstance($request->getByType('sourceModule', \App\Purifier::ALNUM));

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 assigning values to variables in if clauses and the like (line '67', column '12').
Open

    public function getStructure(string $moduleName = null, ?string $referenceFieldName = null): array
    {
        $structures = [];
        foreach (\Vtiger_Module_Model::getInstance($moduleName)->getFields() as $fieldModel) {
            if ($fieldModel->isViewable() && $fieldModel->isListviewSortable()) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

The method getStructure uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $fieldModel = clone $fieldModel;
                    $fieldModel->set('source_field_name', $referenceFieldName);
                    $structures[$fieldModel->getBlockName()][$fieldModel->getName()] = $fieldModel;
                }

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

Reference to undeclared property \Settings_CustomView_SortOrderModal_View->modalIcon
Open

        $this->modalIcon = 'fas fa-sort';

Call to undeclared method \Settings_CustomView_SortOrderModal_View::checkAndConvertJsScripts
Open

        return array_merge($this->checkAndConvertJsScripts([

Static call to undeclared method \App\Controller\ModalSettings::preProcessAjax
Open

        parent::preProcessAjax($request);

Argument 1 (moduleName) is false but \Settings_CustomView_SortOrderModal_View::getStructure() takes null|string defined at /code/modules/Settings/CustomView/views/SortOrderModal.php:59
Open

        $viewer->assign('RECORD_STRUCTURES', $this->getStructure($sourceModuleModel->getName()));

Call to undeclared method \Settings_CustomView_SortOrderModal_View::getViewer
Open

        $viewer = $this->getViewer($request);

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

class Settings_CustomView_SortOrderModal_View extends \App\Controller\ModalSettings

The class Settings_CustomView_SortOrderModal_View is not named in CamelCase.
Open

class Settings_CustomView_SortOrderModal_View extends \App\Controller\ModalSettings
{
    /** {@inheritdoc} */
    protected $pageTitle = 'LBL_SORTING_SETTINGS';

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

    /** {@inheritdoc} */

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 getStructure(string $moduleName = null, ?string $referenceFieldName = null): array

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

        $structures = [];

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

                    $structures[$fieldModel->getBlockName()][$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

    protected $pageTitle = 'LBL_SORTING_SETTINGS';

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

    public function preProcessAjax(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

    public function getModalScripts(App\Request $request)

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

    /** {@inheritdoc} */

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

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

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

                                $structures[$relatedModuleName][$fieldModel->getName()] = $structure;

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

        $viewer->assign('SOURCE_MODULE', $sourceModuleModel->getName());

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 ($fieldModel->isViewable() && $fieldModel->isListviewSortable()) {

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

    public $successBtn = 'LBL_SET';

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

        $viewer->assign('SOURCE_MODULE_MODEL', $sourceModuleModel);

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

    /**

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

     * The function returns module fields together with the related module fields.

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

                if (null === $referenceFieldName) {

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

                    }

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

                    $structures[$moduleName][0][$fieldModel->getBlockName()][$fieldModel->getName()] = $fieldModel;

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

                    $fieldModel->set('source_field_name', $referenceFieldName);

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

        ]), parent::getModalScripts($request));

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

        $viewer->assign('CVID', $customView->getId());

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

     * @param string|null $referenceFieldName

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

     * @return array

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

     */

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

    /** {@inheritdoc} */

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

        $this->modalIcon = 'fas fa-sort';

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

    /** {@inheritdoc} */

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 string|null $moduleName

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

        $sourceModuleModel = \Vtiger_Module_Model::getInstance($request->getByType('sourceModule', \App\Purifier::ALNUM));

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

     *

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

    /** {@inheritdoc} */

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

    {

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

                        foreach ($fieldModel->getReferenceList() as $relatedModuleName) {

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

            "modules.Vtiger.resources.{$viewName}"

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

        $viewer->assign('RECORD_STRUCTURES', $this->getStructure($sourceModuleModel->getName()));

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

                    $fieldModel = clone $fieldModel;

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

        return $structures;

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

        parent::preProcessAjax($request);

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

        return array_merge($this->checkAndConvertJsScripts([

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->assign('SORT_ORDER_BY', $customView->getSortOrderBy());

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

                            }

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

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

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

        $customView = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

        $viewer->view('SortOrderModal.tpl', $moduleName);

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

    {

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

        foreach (\Vtiger_Module_Model::getInstance($moduleName)->getFields() as $fieldModel) {

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

                    if ($fieldModel->isReferenceField()) {

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

    }

Line exceeds 120 characters; contains 122 characters
Open

        $sourceModuleModel = \Vtiger_Module_Model::getInstance($request->getByType('sourceModule', \App\Purifier::ALNUM));

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

                            if ($structure = $this->getStructure($relatedModuleName, $fieldModel->getName())) {

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

class Settings_CustomView_SortOrderModal_View extends \App\Controller\ModalSettings

There are no issues that match your filters.

Category
Status