Avoid using static access to class 'Vtiger_Inventory_Model' in method 'step1'. Open
$instance = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));
- 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_Inventory_Model' in method 'step2'. Open
$inventory = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));
- 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
The method step2 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$fieldInstance = $inventory->getFieldCleanInstance($request->getByType('type', 'Standard'));
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Define a constant instead of duplicating this literal "Standard" 3 times. Open
$instance = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));
- 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.
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_MODELS', $instance->getFieldsTypes());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('FIELD_INSTANCE', $fieldInstance);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('FIELDS_EXISTS', $instance->getFields());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('INVENTORY_MODEL', $inventory);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('BLOCK', $request->getInteger('block'));
- Exclude checks
Avoid excessively long class names like Settings_LayoutEditor_CreateInventoryFields_View. Keep class name length under 40. Open
class Settings_LayoutEditor_CreateInventoryFields_View extends Settings_Vtiger_IndexAjax_View
{
/** {@inheritdoc} */
public function __construct()
{
- 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 Settings_LayoutEditor_CreateInventoryFields_View extends Settings_Vtiger_IndexAjax_View
- Exclude checks
The class Settings_LayoutEditor_CreateInventoryFields_View is not named in CamelCase. Open
class Settings_LayoutEditor_CreateInventoryFields_View extends Settings_Vtiger_IndexAjax_View
{
/** {@inheritdoc} */
public function __construct()
{
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FIELDS_EXISTS', $instance->getFields());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULE_MODELS', $instance->getFieldsTypes());
- 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
$instance = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldInstance = $inventory->getField($request->getByType('fieldName', 'Alnum'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('INVENTORY_MODEL', $inventory);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->exposeMethod('step1');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('BLOCK', $request->getInteger('block'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('CreateInventoryFieldsStep1.tpl', $request->getModule(false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function step2(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FIELD_INSTANCE', $fieldInstance);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('CreateInventoryFieldsStep2.tpl', $request->getModule(false));
- 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->exposeMethod('step2');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$inventory = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::__construct();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has('fieldName')) {
- 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 step1(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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldInstance = $inventory->getFieldCleanInstance($request->getByType('type', 'Standard'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Class name "Settings_LayoutEditor_CreateInventoryFields_View" is not in camel caps format Open
class Settings_LayoutEditor_CreateInventoryFields_View extends Settings_Vtiger_IndexAjax_View
- Exclude checks