YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/LayoutEditor/views/CreateInventoryFields.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Avoid using static access to class 'Vtiger_Inventory_Model' in method 'step1'.
Open

        $instance = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));

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'));

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'));
        }

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'));

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());

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('FIELD_INSTANCE', $fieldInstance);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('FIELDS_EXISTS', $instance->getFields());

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('INVENTORY_MODEL', $inventory);

Call to undeclared method \Vtiger_Viewer::assign
Open

        $viewer->assign('BLOCK', $request->getInteger('block'));

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()
    {

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

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()
    {

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

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public function __construct()

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->assign('FIELDS_EXISTS', $instance->getFields());

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer = $this->getViewer($request);

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->assign('MODULE_MODELS', $instance->getFieldsTypes());

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $instance = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));

Spaces must be used to indent lines; tabs are not allowed
Open

            $fieldInstance = $inventory->getField($request->getByType('fieldName', 'Alnum'));

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->assign('INVENTORY_MODEL', $inventory);

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->exposeMethod('step1');

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->assign('BLOCK', $request->getInteger('block'));

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->view('CreateInventoryFieldsStep1.tpl', $request->getModule(false));

Spaces must be used to indent lines; tabs are not allowed
Open

    public function step2(App\Request $request)

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->assign('FIELD_INSTANCE', $fieldInstance);

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer->view('CreateInventoryFieldsStep2.tpl', $request->getModule(false));

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->exposeMethod('step2');

Spaces must be used to indent lines; tabs are not allowed
Open

        $inventory = Vtiger_Inventory_Model::getInstance($request->getByType('sourceModule', 'Standard'));

Spaces must be used to indent lines; tabs are not allowed
Open

        parent::__construct();

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($request->has('fieldName')) {

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public function step1(App\Request $request)

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /** {@inheritdoc} */

Spaces must be used to indent lines; tabs are not allowed
Open

        } else {

Spaces must be used to indent lines; tabs are not allowed
Open

            $fieldInstance = $inventory->getFieldCleanInstance($request->getByType('type', 'Standard'));

Spaces must be used to indent lines; tabs are not allowed
Open

        $viewer = $this->getViewer($request);

Class name "Settings_LayoutEditor_CreateInventoryFields_View" is not in camel caps format
Open

class Settings_LayoutEditor_CreateInventoryFields_View extends Settings_Vtiger_IndexAjax_View

There are no issues that match your filters.

Category
Status