YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/widgets/CountRecords.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Avoid using static access to class 'Vtiger_Record_Model' in method 'getCountRecords'.
Open

        $parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);

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_RelationListView_Model' in method 'getCountRecords'.
Open

            $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $relatedModuleName);

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\Module' in method 'getCountRecords'.
Open

            if (!\App\Module::isModuleActive($relatedModuleName) || !$relationListView->getRelationModel()) {

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

Define a constant instead of duplicating this literal "relatedModules" 4 times.
Open

        if (isset($this->Data['relatedModules'])) {

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Reference to undeclared property \Vtiger_CountRecords_Widget->Data
Open

        if (isset($this->Data['relatedModules'])) {

Reference to undeclared property \Vtiger_CountRecords_Widget->Data
Open

            foreach ($this->Data['relatedModules'] as $module) {

Reference to undeclared property \Vtiger_CountRecords_Widget->Data
Open

        $this->Config['relatedModules'] = $this->Data['relatedModules'];

Suspicious type false of a variable or expression used to build a string. (Expected type to be able to cast to a string)
Open

        $url = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showCountRecords';

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

class Vtiger_CountRecords_Widget extends Vtiger_Basic_Widget

The class Vtiger_CountRecords_Widget is not named in CamelCase.
Open

class Vtiger_CountRecords_Widget extends Vtiger_Basic_Widget
{
    public $allowedModules = ['Campaigns'];

    public function getUrl()

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

    public function getUrl()

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

    {

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

                $url .= '&relatedModules[]=' . $module;

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

    {

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

        return $countRecords;

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

        $url = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showCountRecords';

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

        $this->Config['relatedModules'] = $this->Data['relatedModules'];

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

        return 'CountRecordsConfig';

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 $allowedModules = ['Campaigns'];

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

            $countRecords[$relatedModuleName] = (int) $relationListView->getRelatedEntriesCount();

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

        $this->Config['url'] = $this->getUrl();

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

                continue;

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 getWidget()

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->Config['tpl'] = 'CountRecords.tpl';

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

        }

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

        return $this->Config;

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

        $countRecords = [];

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 getConfigTplName()

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

        foreach ($modules 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

    public static function getCountRecords($modules, $recordId)

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 (isset($this->Data['relatedModules'])) {

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 ($this->Data['relatedModules'] as $module) {

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

            $relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $relatedModuleName);

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

            if (!\App\Module::isModuleActive($relatedModuleName) || !$relationListView->getRelationModel()) {

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

            }

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

        return $url;

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

        $parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);

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

            }

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

class Vtiger_CountRecords_Widget extends Vtiger_Basic_Widget

There are no issues that match your filters.

Category
Status