Missing class import via use statement (line '79', column '22'). Open
$dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')
- Read upRead up
- Exclude checks
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 '130', column '22'). Open
$widgetModel = new \Vtiger_MiniList_Model();
- Read upRead up
- Exclude checks
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 '162', column '22'). Open
$widgetModel = new \Vtiger_ChartFilter_Model();
- Read upRead up
- Exclude checks
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\Module' in method 'getData'. Open
'vtiger_module_dashboard_blocks.tabid' => Module::getModuleId($this->moduleName),
- 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\Language' in method 'getMiniList'. Open
$headers[$fieldName] = Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());
- 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\Language' in method 'getTabs'. Open
'name' => \App\Language::translate($dashboard['name'], $this->moduleName),
- 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_Widget_Model' in method 'getMiniList'. Open
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- 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_Widget_Model' in method 'getChartFilter'. Open
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- 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\Language' in method 'getMiniList'. Open
'title' => \App\Language::translate($widgetModel->getTitle(), $widgetModel->getTargetModule()),
- 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 "linklabel" 4 times. Open
if (isset(self::$supportedWidgetsTypes[$row['linklabel']])) {
- 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.
null
passed to foreach instead of array Open
foreach ($headerFields as $fieldName => $fieldModel) {
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$query = (new Query())->select(['vtiger_module_dashboard.*', 'vtiger_links.linklabel'])
- Exclude checks
Call to method getInstanceFromValues
from undeclared class \Vtiger_Widget_Model
Open
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- Exclude checks
Call to method getInstanceFromValues
from undeclared class \Vtiger_Widget_Model
Open
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')
- Exclude checks
null
passed to foreach instead of array Open
foreach ($widgetModel->getRecords('all') as $recordModel) {
- Exclude checks
null
passed to foreach instead of array Open
foreach ($headerFields as $fieldName => $fieldModel) {
- Exclude checks
Avoid excessively long variable names like $supportedWidgetsTypes. Keep variable name length under 20. Open
public static $supportedWidgetsTypes = [
'Mini List' => 'getMiniList',
'ChartFilter' => 'getChartFilter',
];
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string[] Id application. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $dashboardType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'ChartFilter' => 'getChartFilter',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $application;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set dashboard ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tabs = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_module_dashboard_blocks', 'vtiger_module_dashboard_blocks.id = vtiger_module_dashboard.blockid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headers[$fieldName] = Language::translate($fieldModel->getFieldLabel(), $fieldModel->getModuleName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgetModel = new \Vtiger_ChartFilter_Model();
- 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
/** @var int Id application. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get instance.
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->select(['u_#__dashboard_type.*'])->from('u_#__dashboard_type')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_module_dashboard_blocks', 'u_#__dashboard_type.dashboard_id = vtiger_module_dashboard_blocks.dashboard_id')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_module_dashboard_blocks.authorized' => $this->application])
- 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
]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgets[] = $this->{self::$supportedWidgetsTypes[$row['linklabel']]}($row);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new static();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $dashboardType
- 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 $tabs;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getData(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_module_dashboard_blocks.tabid' => Module::getModuleId($this->moduleName),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(self::$supportedWidgetsTypes[$row['linklabel']])) {
- 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
* @param array $row
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($widgetModel->getRecords('all') as $recordModel) {
- 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
'data' => [
- 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
'typeChart' => $widgetModel->getType(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'widgetData' => $widgetModel->getChartData(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setDashboard(int $dashboardType): self
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $query->createCommand()->query();
- 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
$headers = $records = [];
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
$records[$recordModel->getId()][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'headers' => $headers,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'records' => $records,
- 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
* Get chart filter widget data.
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $supportedWidgetsTypes = [
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets tabs.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($dashboard = $dataReader->read()) {
- 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
'Mini List' => 'getMiniList',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- 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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getTabs(): array
- 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
'system' => $dashboard['system'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getMiniList(array $row): array
- 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
'name' => \App\Language::translate($dashboard['name'], $this->moduleName),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_module_dashboard_blocks.authorized' => $this->application,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgetModel = new \Vtiger_MiniList_Model();
- 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
$records[$recordModel->getId()][$fieldName] = $recordModel->getDisplayValue($fieldName, $recordModel->getId(), true);
- 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
/** @var string Module name. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'title' => \App\Language::translate($widgetModel->getTitle(), $widgetModel->getTargetModule()),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'data' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $moduleName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var int Type of dashboard. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->moduleName = $moduleName;
- 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->dashboardType = $dashboardType;
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
->innerJoin('vtiger_module_dashboard_blocks', 'u_#__dashboard_type.dashboard_id = vtiger_module_dashboard_blocks.dashboard_id')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
->innerJoin('vtiger_module_dashboard_blocks', 'vtiger_module_dashboard_blocks.id = vtiger_module_dashboard.blockid')
- 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
/**
- 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
->innerJoin('vtiger_links', 'vtiger_links.linkid = vtiger_module_dashboard.linkid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_module_dashboard_blocks.dashboard_id' => $this->dashboardType,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $row
- 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
'filterIds' => $widgetModel->getFilterIds(),
- 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
* @param int $application
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbId = $dashboard['dashboard_id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgets = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerFields = $widgetModel->getHeaders();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getChartFilter(array $row): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $dashboardType
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->distinct()->createCommand()->query();
- 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
$query = (new Query())->select(['vtiger_module_dashboard.*', 'vtiger_links.linklabel'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_module_dashboard')
- 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 [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => $row['linklabel'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'stacked' => $widgetModel->isStacked() ? 1 : 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->dashboardType = $dashboardType;
- 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
$tabs[$dbId] = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $dbId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['linkid'] = $row['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- 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 ($headerFields as $fieldName => $fieldModel) {
- 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
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance(string $moduleName, int $dashboardType, int $application): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Return data about all added widgets in this dashboard.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($headerFields as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => $row['linklabel'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'colorsFromDividingField' => $widgetModel->areColorsFromDividingField() ? 1 : 0,
- 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
$instance->application = $application;
- 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
}
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $widgets;
- 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
* Get mini list widget data.
- 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
'modulename' => $widgetModel->getTargetModule(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instance;
- 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 array
- 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
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgetModel->setWidgetModel(\Vtiger_Widget_Model::getInstanceFromValues($row));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulename' => $widgetModel->getTargetModule(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'title' => $widgetModel->getTitle(),
- Exclude checks