YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/inventoryfields/PicklistField.php

Summary

Maintainability
A
55 mins
Test Coverage
F
0%

Function getPicklistValues has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function getPicklistValues(string $moduleName): array
    {
        $modules = $this->getParamsConfig();
        if ($moduleName) {
            foreach ($modules as $module => $field) {
Severity: Minor
Found in modules/Vtiger/inventoryfields/PicklistField.php - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid using static access to class 'Vtiger_Module_Model' in method 'getPicklist'.
Open

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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\Fields\Picklist' in method 'getPicklistValues'.
Open

            foreach (App\Fields\Picklist::getValuesName($field) as $value) {

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 assigning values to variables in if clauses and the like (line '32', column '7').
Open

    public function getParams()
    {
        $params = [];
        $inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());
        if ($field = $inventory->getField('name')) {

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

Avoid using static access to class '\App\Language' in method 'getPicklist'.
Open

            $values[$fieldName] = \App\Language::translate($fieldModel->get('label'), $moduleName);

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 'getPicklistValues'.
Open

                    'name' => \App\Language::translate($value, $module, false, false),

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 'getParams'.
Open

        $inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());

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

Argument 3 (language) is false but \App\Language::translate() takes null|string defined at /code/app/Language.php:161
Open

                    'name' => \App\Language::translate($value, $module, false, false),

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Vtiger_PicklistField_InventoryField extends Vtiger_Basic_InventoryField

The class Vtiger_PicklistField_InventoryField is not named in CamelCase.
Open

class Vtiger_PicklistField_InventoryField extends Vtiger_Basic_InventoryField
{
    protected $type = 'PicklistField';
    protected $defaultLabel = 'LBL_PICKLIST_FIELD';
    protected $columnName = 'picklistfield';

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

    public function getParams()

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

    public function getPicklist($moduleName)

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

        foreach ($moduleModel->getFieldsByType(['picklist']) as $fieldName => $fieldModel) {

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

        if ($moduleName) {

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

                $values[] = [

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

    protected $columnName = 'picklistfield';

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

    {

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

            $params = $field->getParamsConfig()['modules'] ?? [];

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);

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

                if ($module != $moduleName) {

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

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

        $params = [];

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

        $values = [];

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

        foreach ($modules as $module => $field) {

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

    protected $onlyOne = false;

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

        return 'inventoryTypes/PicklistField.tpl';

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 getPicklistValues(string $moduleName): array

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

    {

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

                    'module' => $module,

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

    protected $dbType = 'string';

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

    }

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

                    'value' => $value,

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

        return $params;

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

    protected $type = 'PicklistField';

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

     *

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

        $values = [];

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

            }

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

    protected $defaultLabel = 'LBL_PICKLIST_FIELD';

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

        return $values;

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

     * @return array

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

    {

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

        if ($field = $inventory->getField('name')) {

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

                    'name' => \App\Language::translate($value, $module, false, 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

        return $values;

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

    }

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

    protected $purifyType = \App\Purifier::TEXT;

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

     *

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

                    unset($modules[$module]);

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

            foreach ($modules as $module => $field) {

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

        $inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());

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

     * Gets picklist values.

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

     */

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

            foreach (App\Fields\Picklist::getValuesName($field) as $value) {

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

        }

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

            $values[$fieldName] = \App\Language::translate($fieldModel->get('label'), $moduleName);

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

     * @param string $moduleName

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

        $modules = $this->getParamsConfig();

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

                ];

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

class Vtiger_PicklistField_InventoryField extends Vtiger_Basic_InventoryField

There are no issues that match your filters.

Category
Status