Avoid using undefined variables such as '$data' which will lead to PHP notices. Open
$data[$fieldName] = $value ? explode(' |##| ', $value) : [];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$data' which will lead to PHP notices. Open
$this->set('data', \App\Json::encode($data));
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using static access to class '\App\Language' in method 'getTitle'. Open
return \App\Language::translate($this->get('linklabel'), 'Dashboard');
- 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\Json' in method 'getFieldInstanceByName'. Open
$data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];
- 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_Field_Model' in method 'getFieldInstanceByName'. Open
return \Vtiger_Field_Model::init($moduleName, $params, $name);
- 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\Json' in method 'setDataFromRequest'. Open
$this->set('data', \App\Json::encode($data));
- 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 "label" 6 times. Open
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- 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.
Define a constant instead of duplicating this literal "purifyType" 5 times. Open
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- 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.
Define a constant instead of duplicating this literal "default_time" 3 times. Open
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- 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 class \Vtiger_Widget_Model
Open
return parent::getFieldInstanceByName($name);
- Exclude checks
Reference to undeclared class \Vtiger_Widget_Model
Open
parent::setDataFromRequest($request);
- Exclude checks
Class extends undeclared class \Vtiger_Widget_Model
Open
class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
- Exclude checks
Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::get
Open
$data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];
- Exclude checks
Variable $data
was undeclared, but array fields are being added to it. Open
$data[$fieldName] = $value ? explode(' |##| ', $value) : [];
- Exclude checks
Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::get
Open
return \App\Language::translate($this->get('linklabel'), 'Dashboard');
- Exclude checks
Call to undeclared method \OSSTimeControl_TimeCounterModel_Dashboard::set
Open
$this->set('data', \App\Json::encode($data));
- Exclude checks
Invalid offset "tooltip"
of array type array{label:'LBL_DEFAULT_TIME',purifyType:'Text'}
Open
'tooltip' => $this->customFields[$name]['tooltip'] ?? ''
- Exclude checks
Avoid excessively long class names like OSSTimeControl_TimeCounterModel_Dashboard. Keep class name length under 40. Open
class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
{
/** {@inheritdoc} */
public $customFields = [
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
- Exclude checks
The class OSSTimeControl_TimeCounterModel_Dashboard is not named in CamelCase. Open
class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
{
/** {@inheritdoc} */
public $customFields = [
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getEditFields(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = 'Settings:WidgetsManagement';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset($this->customFields[$name])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => $this->customFields[$name]['label'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $editFields = [
- 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
'tooltip' => $this->customFields[$name]['tooltip'] ?? ''
- 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 ('default_time' === $name) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'width' => ['label' => 'LBL_WIDTH', 'purifyType' => \App\Purifier::INTEGER],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldInstanceByName($name)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $customFields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'isdefault' => ['label' => 'LBL_MANDATORY_WIDGET', 'purifyType' => \App\Purifier::BOOL],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'height' => ['label' => 'LBL_HEIGHT', 'purifyType' => \App\Purifier::INTEGER],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->editFields + $this->customFields;
- 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
$params['uitype'] = 33;
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::getFieldInstanceByName($name);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name' => $name,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = $this->get('data') ? \App\Json::decode($this->get('data')) : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'90' => '90',
- 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
'default_time' => ['label' => 'LBL_DEFAULT_TIME', 'purifyType' => \App\Purifier::TEXT],
- 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
$params['typeofdata'] = 'V~O';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['picklistValues'] = [
- 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 \Vtiger_Field_Model::init($moduleName, $params, $name);
- 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
$value = $fieldModel->getDBValue($value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \App\Language::translate($this->get('linklabel'), 'Dashboard');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'30' => '30',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setDataFromRequest(App\Request $request)
- 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 getTitle()
- 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
$params['fieldvalue'] = implode(' |##| ', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $this->getFieldInstanceByName($fieldName)->getUITypeModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- 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
'40' => '40',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data[$fieldName] = $value ? explode(' |##| ', $value) : [];
- 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
'15' => '15',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'60' => '60',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->customFields as $fieldName => $fieldInfo) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has($fieldName) && 'default_time' === $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel->validate($value, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->set('data', \App\Json::encode($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
$value = $data[$name] ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::setDataFromRequest($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $request->getByType($fieldName, $fieldInfo['purifyType']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "OSSTimeControl_TimeCounterModel_Dashboard" is not in camel caps format Open
class OSSTimeControl_TimeCounterModel_Dashboard extends Vtiger_Widget_Model
- Exclude checks