YetiForceCompany/YetiForceCRM

View on GitHub
modules/Project/dashboards/ProjectWidget.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function getSearchParams has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getSearchParams($stage, $assignedto, $dates)
    {
        $listSearchParams = [];
        $conditions = [];
        array_push($conditions, ['sales_stage', 'e', $stage]);
Severity: Minor
Found in modules/Project/dashboards/ProjectWidget.php - About 25 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 unused parameters such as '$request'.
Open

    public function getHeaderCss(App\Request $request)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('MODULE_NAME', $moduleName);

Call to method getGroupName from undeclared class \App\Fields\Owner
Open

                $groupName = \App\Fields\Owner::getGroupName($assignedto);

Call to undeclared method \Vtiger_Viewer::assign
Open

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

Call to method getUserLabel from undeclared class \App\Fields\Owner
Open

                array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);

Call to method getInstance from undeclared class \Vtiger_Widget_Model
Open

        $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

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

        $currentUserId = \App\User::getCurrentUserId();

Call to undeclared method \Vtiger_Module_Model::getProjectWidget
Open

        $data = $moduleModel->getProjectWidget($owner, $dates);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('STYLES', $this->getHeaderCss($request));

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('CURRENTUSER', $currentUserId);

Saw unextractable annotation for comment '* @return <array> - array of Vtiger_CssScript_Model'</array>
Open

     * @return <array> - array of Vtiger_CssScript_Model

Call to method getType from undeclared class \App\Fields\Owner
Open

            $ownerType = \App\Fields\Owner::getType($assignedto);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('DATA', $data);

Avoid using static access to class 'Users_Record_Model' in method 'getSearchParams'.
Open

            $currenUserModel = Users_Record_Model::getCurrentUserModel();

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

        $currentUserId = \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::getInstance($request->getInteger('linkid'), $currentUserId);

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

            $dates = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($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

Avoid using static access to class '\App\Fields\Owner' in method 'getSearchParams'.
Open

                $groupName = \App\Fields\Owner::getGroupName($assignedto);

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

        $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 using static access to class '\App\Fields\Owner' in method 'getSearchParams'.
Open

            $ownerType = \App\Fields\Owner::getType($assignedto);

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

        $dates = \App\Fields\Date::formatRangeToDisplay($dates);

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

            } else {
                $groupName = \App\Fields\Owner::getGroupName($assignedto);
                array_push($conditions, ['assigned_user_id', 'e', $groupName]);
            }

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\Fields\Owner' in method 'getSearchParams'.
Open

                array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);

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 Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View

The class Project_ProjectWidget_Dashboard is not named in CamelCase.
Open

class Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View
{
    /**
     * Retrieves css styles that need to loaded in the page.
     *

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

                $groupName = \App\Fields\Owner::getGroupName($assignedto);

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

                array_push($conditions, ['assigned_user_id', 'e', $groupName]);

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

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

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

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

                array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);

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

        $data = $moduleModel->getProjectWidget($owner, $dates);

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

            $data[$i][] = $listViewUrl . $this->getSearchParams($data[$i][0], $owner, $dates);

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

            array_push($conditions, ['closingdate', 'bw', implode(',', $dates)]);

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

        //Include special script and css needed for this widget

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

        if ('all' != $assignedto) {

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

        if (empty($dates)) {

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

            $dates = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($widget);

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

        $moduleModel = Vtiger_Module_Model::getInstance($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

            //Place your widget specific css files here

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

        if ('' == $assignedto) {

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

        $listViewUrl = $moduleModel->getListViewUrl();

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

        $countData = \count($data);

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

        for ($i = 0; $i < $countData; ++$i) {

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

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

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

        return $this->checkAndConvertCssStyles([

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

            $ownerType = \App\Fields\Owner::getType($assignedto);

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

        $listSearchParams[] = $conditions;

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

        $currentUserId = \App\User::getCurrentUserId();

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

    {

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

        $listSearchParams = [];

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

        $widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);

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('CURRENTUSER', $currentUserId);

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 getSearchParams($stage, $assignedto, $dates)

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

        $dates = \App\Fields\Date::formatRangeToDisplay($dates);

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

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

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

     * Retrieves css styles that need to loaded in the page.

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

        $viewer->assign('STYLES', $this->getHeaderCss($request));

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

     * @return <array> - array of Vtiger_CssScript_Model

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

            $currenUserModel = Users_Record_Model::getCurrentUserModel();

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 - request model

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' == $ownerType) {

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

        return '&search_params=' . json_encode($listSearchParams);

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

        $dates = $request->getDateRange('expectedclosedate');

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

            $assignedto = $currenUserModel->getId();

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

        if (!empty($dates)) {

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

        $conditions = [];

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

        array_push($conditions, ['sales_stage', 'e', $stage]);

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

        $viewer->assign('DATA', $data);

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

class Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View

There are no issues that match your filters.

Category
Status