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) {
- Read upRead up
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);
- 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\Fields\Picklist' in method 'getPicklistValues'. Open
foreach (App\Fields\Picklist::getValuesName($field) as $value) {
- 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 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')) {
- 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
Avoid using static access to class '\App\Language' in method 'getPicklist'. Open
$values[$fieldName] = \App\Language::translate($fieldModel->get('label'), $moduleName);
- 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\Language' in method 'getPicklistValues'. Open
'name' => \App\Language::translate($value, $module, false, false),
- 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 'getParams'. Open
$inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());
- 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
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),
- Exclude checks
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
- Exclude checks
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';
- 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
public function getParams()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getPicklist($moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($moduleModel->getFieldsByType(['picklist']) as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($moduleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$values[] = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $columnName = 'picklistfield';
- 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 = $field->getParamsConfig()['modules'] ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($module != $moduleName) {
- 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 getEditTemplateName()
- 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
}
- 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
$values = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($modules as $module => $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $onlyOne = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'inventoryTypes/PicklistField.tpl';
- 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 getPicklistValues(string $moduleName): array
- 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
'module' => $module,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $dbType = 'string';
- 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' => $value,
- 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 $params;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $type = 'PicklistField';
- 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
$values = [];
- 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
protected $defaultLabel = 'LBL_PICKLIST_FIELD';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $values;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- 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 ($field = $inventory->getField('name')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name' => \App\Language::translate($value, $module, false, 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
return $values;
- 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
protected $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
unset($modules[$module]);
- 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
foreach ($modules as $module => $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets picklist values.
- 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
foreach (App\Fields\Picklist::getValuesName($field) as $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
$values[$fieldName] = \App\Language::translate($fieldModel->get('label'), $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = $this->getParamsConfig();
- 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 "Vtiger_PicklistField_InventoryField" is not in camel caps format Open
class Vtiger_PicklistField_InventoryField extends Vtiger_Basic_InventoryField
- Exclude checks