YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/BusinessHours/views/List.php

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        if ($request->isJSON()) {
            $response = new Vtiger_Response();
            $listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));
Severity: Minor
Found in modules/Settings/BusinessHours/views/List.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

Missing class import via use statement (line '51', column '52').
Open

            foreach ($listViewModel->getListViewEntries(new Vtiger_Paging_Model()) as $recordModel) {

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

Missing class import via use statement (line '48', column '20').
Open

            $response = new Vtiger_Response();

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

Missing class import via use statement (line '23', column '22').
Open

        $pagingModel = new Vtiger_Paging_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

Avoid using static access to class '\App\Language' in method 'getBreadcrumbTitle'.
Open

        return \App\Language::translate('LBL_BUSINESS_HOURS', $request->getModule(false));

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

            $response->setResult(\App\Json::encode($rows));

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

            $listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));

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 {
            $viewer = $this->getViewer($request);
            $this->initializeListViewContents($request, $viewer);
            $viewer->view('ListViewContents.tpl', $request->getModule(false));
        }

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_Vtiger_ListView_Model' in method 'initializeListViewContents'.
Open

        $listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));

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 unused local variables such as '$value'.
Open

                foreach ($data as $name => $value) {

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open

            $this->listViewLinks = $listViewModel->getListViewLinks();

Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open

        $viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('QUALIFIED_MODULE', $request->getModule(false));

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('PAGING_MODEL', $pagingModel);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('LISTVIEW_HEADERS', $this->listViewHeaders);

Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open

        if (!isset($this->listViewLinks)) {

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('MODULE_MODEL', $module);

Assigning array to property but \Settings_BusinessHours_List_View->listViewHeaders is false
Open

            $this->listViewHeaders = $listViewModel->getListViewHeaders();

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('COLUMN_NAME', '');

Assigning \Settings_Vtiger_Record_Model[] to property but \Settings_BusinessHours_List_View->listViewEntries is false
Open

            $this->listViewEntries = $listViewModel->getListViewEntries($pagingModel);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('LISTVIEW_ENTRIES', $this->listViewEntries);

Argument 1 (var) is false but \count() takes \Countable|array
Open

        $viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));

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

class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View

The class Settings_BusinessHours_List_View is not named in CamelCase.
Open

class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View
{
    /** {@inheritdoc} */
    public function getBreadcrumbTitle(App\Request $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

        $pagingModel = new Vtiger_Paging_Model();

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

            $this->listViewLinks = $listViewModel->getListViewLinks();

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

        if (!$this->listViewHeaders) {

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

        if (!isset($this->listViewLinks)) {

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

        if ($request->isJSON()) {

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

        return \App\Language::translate('LBL_BUSINESS_HOURS', $request->getModule(false));

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

            $response = new Vtiger_Response();

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

        $listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));

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

        $module = $listViewModel->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

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

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

            $this->initializeListViewContents($request, $viewer);

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 initializeListViewContents(App\Request $request, Vtiger_Viewer $viewer)

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

            $this->listViewEntries = $listViewModel->getListViewEntries($pagingModel);

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('PAGING_MODEL', $pagingModel);

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

        $viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));

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

                $rows[] = $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

    }

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

            $response->setResult(\App\Json::encode($rows));

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

                $data = $recordModel->getData();

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 getBreadcrumbTitle(App\Request $request)

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

            $this->listViewHeaders = $listViewModel->getListViewHeaders();

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

        $viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);

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

        $viewer->assign('QUALIFIED_MODULE', $request->getModule(false));

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

                    $data[$name] = $recordModel->getDisplayValue($name);

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 (!$this->listViewEntries) {

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('COLUMN_NAME', '');

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

        $viewer->assign('LISTVIEW_HEADERS', $this->listViewHeaders);

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

            $rows = [];

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 ($data as $name => $value) {

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

            $response->emit();

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('MODULE_MODEL', $module);

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

        $viewer->assign('LISTVIEW_ENTRIES', $this->listViewEntries);

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

            foreach ($listViewModel->getListViewEntries(new Vtiger_Paging_Model()) as $recordModel) {

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

            $listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));

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

            }

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

class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View

There are no issues that match your filters.

Category
Status