YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/views/SortOrderModal.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $moduleName = $request->getModule();
        $view = $request->getByType('fromView', \App\Purifier::STANDARD);
        $sourceModuleModel = Vtiger_Module_Model::getInstance($moduleName);
Severity: Minor
Found in modules/Vtiger/views/SortOrderModal.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

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

    private function getStructure(string $moduleName, ?Vtiger_Field_Model $referenceField = null): array
    {
        $structure = [];
        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
        foreach ($moduleModel->getFields() as $fieldModel) {
Severity: Minor
Found in modules/Vtiger/views/SortOrderModal.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 undefined variables such as '$structures' which will lead to PHP notices.
Open

        $structures[$moduleName][] = $this->getStructure($moduleName);

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$structures' which will lead to PHP notices.
Open

        $viewer->assign('RECORD_STRUCTURES', $structures);

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$structures' which will lead to PHP notices.
Open

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

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Missing class import via use statement (line '29', column '14').
Open

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

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

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

        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);

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 '51', column '11').
Open

    public function process(App\Request $request)
    {
        $moduleName = $request->getModule();
        $view = $request->getByType('fromView', \App\Purifier::STANDARD);
        $sourceModuleModel = Vtiger_Module_Model::getInstance($moduleName);

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

Call to undeclared method \Vtiger_SortOrderModal_View::getViewer
Open

        $viewer = $this->getViewer($request);
Severity: Critical
Found in modules/Vtiger/views/SortOrderModal.php by phan

Argument 1 (mixed) is string but \Users_Privileges_Model::hasModulePermission() takes int defined at /code/modules/Users/models/Privileges.php:101
Open

        if (!Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule()) ||

Variable $structures was undeclared, but array fields are being added to it.
Open

        $structures[$moduleName][] = $this->getStructure($moduleName);

Reference to undeclared class \App\Controller\Modal
Open

        parent::preProcessAjax($request);
Severity: Critical
Found in modules/Vtiger/views/SortOrderModal.php by phan

Class extends undeclared class \App\Controller\Modal
Open

class Vtiger_SortOrderModal_View extends \App\Controller\Modal
Severity: Critical
Found in modules/Vtiger/views/SortOrderModal.php by phan

Reference to undeclared property \Vtiger_SortOrderModal_View->modalIcon
Open

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

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

class Vtiger_SortOrderModal_View extends \App\Controller\Modal

The class Vtiger_SortOrderModal_View is not named in CamelCase.
Open

class Vtiger_SortOrderModal_View extends \App\Controller\Modal
{
    /** {@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

        parent::preProcessAjax($request);

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

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

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

            foreach ($sourceModuleModel->getFieldsByReference() as $referenceField) {

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('MODULE_NAME', $moduleName);

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

        return $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

            !\Vtiger_Module_Model::getInstance($request->getModule())->isAdvSortEnabled()) {

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

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

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

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

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

        $structures[$moduleName][] = $this->getStructure($moduleName);

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

                if ($referenceField) {

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

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

    public function preProcessAjax(App\Request $request)

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

        if ('Detail' !== $view) {

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

                    $fieldModel->set('source_field_name', $referenceField->getName());

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

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

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

        foreach ($moduleModel->getFields() as $fieldModel) {

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

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

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

                $structure[$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

        $moduleName = $request->getModule();

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 ($referenceField->isViewable()) {

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->view('Modals/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

        $structure = [];

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

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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('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

                $fieldModel = clone $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

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

    }

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

                    }

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

    private function getStructure(string $moduleName, ?Vtiger_Field_Model $referenceField = null): array

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

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

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

        $viewer->assign('RECORD_STRUCTURES', $structures);

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 (!Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule()) ||

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

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

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

        $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);

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

class Vtiger_SortOrderModal_View extends \App\Controller\Modal

There are no issues that match your filters.

Category
Status