Avoid using static access to class 'Vtiger_Record_Model' in method 'getCountRecords'. Open
$parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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()) {
- Read upRead up
- Exclude checks
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'])) {
- Read upRead up
- Exclude checks
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'])) {
- Exclude checks
Reference to undeclared property \Vtiger_CountRecords_Widget->Data
Open
foreach ($this->Data['relatedModules'] as $module) {
- Exclude checks
Reference to undeclared property \Vtiger_CountRecords_Widget->Data
Open
$this->Config['relatedModules'] = $this->Data['relatedModules'];
- Exclude checks
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';
- Exclude checks
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
- Exclude checks
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()
- Read upRead up
- Exclude checks
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()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url .= '&relatedModules[]=' . $module;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $countRecords;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$url = 'module=' . $this->Module . '&view=Detail&record=' . $this->Record . '&mode=showCountRecords';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['relatedModules'] = $this->Data['relatedModules'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'CountRecordsConfig';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $allowedModules = ['Campaigns'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$countRecords[$relatedModuleName] = (int) $relationListView->getRelatedEntriesCount();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['url'] = $this->getUrl();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getWidget()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->Config['tpl'] = 'CountRecords.tpl';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->Config;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$countRecords = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getConfigTplName()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($modules as $relatedModuleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getCountRecords($modules, $recordId)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($this->Data['relatedModules'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->Data['relatedModules'] as $module) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView = Vtiger_RelationListView_Model::getInstance($parentRecordModel, $relatedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Module::isModuleActive($relatedModuleName) || !$relationListView->getRelationModel()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $url;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Vtiger_CountRecords_Widget" is not in camel caps format Open
class Vtiger_CountRecords_Widget extends Vtiger_Basic_Widget
- Exclude checks