YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/dashboards/MiniList.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    public function process(App\Request $request, $widget = null)
    {
        $viewer = $this->getViewer($request);
        $moduleName = $request->getModule();
        $data = $request->getAll();
Severity: Minor
Found in modules/Vtiger/dashboards/MiniList.php - About 2 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

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

    public function process(App\Request $request, $widget = null)
    {
        $viewer = $this->getViewer($request);
        $moduleName = $request->getModule();
        $data = $request->getAll();
Severity: Major
Found in modules/Vtiger/dashboards/MiniList.php - About 2 hrs to fix

    The method process() has an NPath complexity of 216. The configured NPath complexity threshold is 200.
    Open

        public function process(App\Request $request, $widget = null)
        {
            $viewer = $this->getViewer($request);
            $moduleName = $request->getModule();
            $data = $request->getAll();

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

    Source https://phpmd.org/rules/codesize.html#npathcomplexity

    The method process() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
    Open

        public function process(App\Request $request, $widget = null)
        {
            $viewer = $this->getViewer($request);
            $moduleName = $request->getModule();
            $data = $request->getAll();

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

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

        public function process(App\Request $request, $widget = null)

    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

    Missing class import via use statement (line '33', column '30').
    Open

            $miniListWidgetModel = new Vtiger_MiniList_Model();

    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

    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 {
                $widget->set('title', $miniListWidgetModel->getTitle());
                $viewer->view('dashboards/MiniList.tpl', $moduleName);
            }

    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

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

                $owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

    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 {
                $widgetId = $request->getInteger('widgetid');
            }

    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

    Avoid using static access to class '\App\User' in method 'process'.
    Open

            $widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());

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

            $widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());

    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 {
                $owner = $request->getByType('owner', \App\Purifier::TEXT);
            }

    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

    Avoid using static access to class '\App\Json' in method 'process'.
    Open

                $widgetParams = \App\Json::decode($widget->get('data'));

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

            $searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_params'));

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

                    $filterField = Vtiger_Field_Model::getInstanceFromFieldId($widgetParams['filterFields']);

    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

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('MODULE_NAME', $moduleName);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('WIDGET', $widget);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('MINILIST_WIDGET_MODEL', $miniListWidgetModel);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('FILTER_FIELD', $filterField);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to method getInstanceWithWidgetId from undeclared class \Vtiger_Widget_Model
    Open

            $widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

            $widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('OWNER', $owner);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('FIELD_HREF', $fieldHref);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SEARCH_DETAILS', $searchParams);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('DATA', $data);
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('BASE_MODULE', $miniListWidgetModel->getTargetModule());
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SCRIPTS', $this->getFooterScripts($request));
    Severity: Critical
    Found in modules/Vtiger/dashboards/MiniList.php by phan

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

    class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View

    The class Vtiger_MiniList_Dashboard is not named in CamelCase.
    Open

    class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View
    {
        public function process(App\Request $request, $widget = null)
        {
            $viewer = $this->getViewer($request);

    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

            if (!$request->has('owner')) {

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

                $widgetId = $widget->get('id');

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

            $widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());

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

            // Initialize Widget to the right-state of information

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

        public function process(App\Request $request, $widget = null)

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

        {

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

                $widgetId = $request->getInteger('widgetid');

    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

            $data = $request->getAll();

    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

            if ($widget && !$request->has('widgetid')) {

    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

                $owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);

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

                $fieldHref = $widgetParams['fieldHref'] ?? false;

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

            $viewer->assign('FIELD_HREF', $fieldHref);

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

            if ($request->has('content')) {

    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 ($fieldListGroup as $fieldSearchInfo) {

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

                if (!empty($widgetParams['filterFields'])) {

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

                $owner = $request->getByType('owner', \App\Purifier::TEXT);

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

            $miniListWidgetModel->setWidgetModel($widget);

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

                $widgetParams = \App\Json::decode($widget->get('data'));

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

        }

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

                        $fieldSearchInfo['searchValue'] = $fieldSearchInfo[2];

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

                        $fieldSearchInfo['fieldName'] = $fieldName = $fieldSearchInfo[0];

    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

                        $fieldSearchInfo['specialOption'] = \in_array($fieldSearchInfo[1], ['ch', 'kh']) ? true : '';

    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('SEARCH_DETAILS', $searchParams);

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

                $widget->set('title', $miniListWidgetModel->getTitle());

    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 ($widget->get('data')) {

    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('MINILIST_WIDGET_MODEL', $miniListWidgetModel);

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

            $viewer->assign('FILTER_FIELD', $filterField);

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

                $viewer->view('dashboards/MiniListContents.tpl', $moduleName);

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

            if (!empty($searchParams) && \is_array($searchParams)) {

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

            }

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

                $miniListWidgetModel->setSearchParams($searchParams);

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

                foreach ($request->getArray('search_params') as $fieldListGroup) {

    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('BASE_MODULE', $miniListWidgetModel->getTargetModule());

    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('DATA', $data);

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

                        $searchParams[$fieldName] = $fieldSearchInfo;

    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

            $searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_params'));

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

                    $filterField = Vtiger_Field_Model::getInstanceFromFieldId($widgetParams['filterFields']);

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

            $viewer->assign('WIDGET', $widget);

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

                $viewer->view('dashboards/MiniListFooter.tpl', $moduleName);

    Line exceeds 120 characters; contains 135 characters
    Open

            $searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_params'));

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

            $fieldHref = $filterField = false;

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

            $miniListWidgetModel = new Vtiger_MiniList_Model();

    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

            $viewer->assign('OWNER', $owner);

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

            $viewer->assign('SCRIPTS', $this->getFooterScripts($request));

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

                $viewer->view('dashboards/MiniList.tpl', $moduleName);

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

    class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View

    There are no issues that match your filters.

    Category
    Status