Missing class import via use statement (line '28', column '17'). Open
$field = new Vtiger_Field_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 assigning values to variables in if clauses and the like (line '17', column '7'). Open
public function getListViewEntries(Vtiger_Paging_Model $pagingModel)
{
if ($currencyId = $this->get('currency_id')) {
$this->getQueryGenerator()->currencyId = $currencyId;
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Define a constant instead of duplicating this literal "listprice" 3 times. Open
$field->set('name', 'listprice');
- 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 instance property currencyId
from undeclared class \App\QueryGenerator
Open
$this->getQueryGenerator()->currencyId = $currencyId;
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class PriceBooks_ListView_Model extends Vtiger_ListView_Model
- Exclude checks
The class PriceBooks_ListView_Model is not named in CamelCase. Open
class PriceBooks_ListView_Model extends Vtiger_ListView_Model
{
/** {@inheritdoc} */
public function getListViewEntries(Vtiger_Paging_Model $pagingModel)
{
- 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
if ($this->get('currency_id')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->set('label', 'List Price');
- 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
$field->set('column', 'listprice');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerFields = parent::getListViewHeaders();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerFields['listprice'] = $field;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($currencyId = $this->get('currency_id')) {
- 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 getListViewHeaders()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $headerFields;
- 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 function getListViewEntries(Vtiger_Paging_Model $pagingModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return parent::getListViewEntries($pagingModel);
- 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
$field = new Vtiger_Field_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
$field->set('typeofdata', 'N~O');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->set('fromOutsideList', true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->getQueryGenerator()->currencyId = $currencyId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->set('name', 'listprice');
- 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
Class name "PriceBooks_ListView_Model" is not in camel caps format Open
class PriceBooks_ListView_Model extends Vtiger_ListView_Model
- Exclude checks