Function removeField
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function removeField(string $moduleName, string $fieldName)
{
$tabId = \App\Module::getModuleId($moduleName);
$dataReader = (new \App\Db\Query())->select(['id'])->from('s_#__fields_dependency')
->orWhere(['and', ['tabid' => $tabId], ['or', ['like', 'fields', "\"{$fieldName}\""], ['like', 'conditionsFields', "\"{$fieldName}\""]]])
- 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
Missing class import via use statement (line '69', column '22'). Open
$dataReader = (new \App\Db\Query())->select(['id'])->from('s_#__fields_dependency')
- 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 using static access to class '\App\Module' in method 'removeField'. Open
$baseModuleName = \App\Module::getModuleName($fieldDepend->get('tabid'));
- 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\Condition' in method 'removeField'. Open
$conditions = \App\Condition::removeFieldFromCondition($baseModuleName, $conditions, $moduleName, $fieldName);
- 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\Json' in method 'removeField'. Open
$conditions = \App\Json::decode($fieldDepend->get('conditions'));
- 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\Module' in method 'removeField'. Open
$tabId = \App\Module::getModuleId($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 'Vtiger_Module_Model' in method 'getSupportedModules'. Open
return Vtiger_Module_Model::getAll([0, 2], [], true);
- 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\Json' in method 'removeField'. Open
$fields = \App\Json::decode($fieldDepend->get('fields'));
- 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 '\Settings_FieldsDependency_Record_Model' in method 'removeField'. Open
$fieldDepend = \Settings_FieldsDependency_Record_Model::getInstanceById($fieldDependId);
- 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 '80', column '20'). Open
public static function removeField(string $moduleName, string $fieldName)
{
$tabId = \App\Module::getModuleId($moduleName);
$dataReader = (new \App\Db\Query())->select(['id'])->from('s_#__fields_dependency')
->orWhere(['and', ['tabid' => $tabId], ['or', ['like', 'fields', "\"{$fieldName}\""], ['like', 'conditionsFields', "\"{$fieldName}\""]]])
- 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 "tabid" 3 times. Open
'tabid' => 'LBL_SOURCE_MODULE',
- 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.
Define a constant instead of duplicating this literal "conditions" 3 times. Open
->orWhere(['like', 'conditions', $fieldName])->createCommand()->query();
- 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.
Define a constant instead of duplicating this literal "fields" 4 times. Open
'fields' => 'LBL_FIELDS',
- 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 \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select(['id'])->from('s_#__fields_dependency')
- Exclude checks
Call to method getInstanceById
from undeclared class \Settings_FieldsDependency_Record_Model
Open
$fieldDepend = \Settings_FieldsDependency_Record_Model::getInstanceById($fieldDependId);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_FieldsDependency_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks
The class Settings_FieldsDependency_Module_Model is not named in CamelCase. Open
class Settings_FieldsDependency_Module_Model extends Settings_Vtiger_Module_Model
{
/** {@inheritdoc} */
public $baseTable = 's_#__fields_dependency';
- 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
/** {@inheritdoc} */
- 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 getDefaultUrl()
- 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
$fieldDepend->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getSupportedModules(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $baseIndex = 'id';
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->orWhere(['like', 'conditions', $fieldName])->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions = \App\Json::decode($fieldDepend->get('conditions'));
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$conditions = \App\Condition::removeFieldFromCondition($baseModuleName, $conditions, $moduleName, $fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($fields[$key]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name' => 'LBL_NAME',
- 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 $baseTable = 's_#__fields_dependency';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'status' => 'FL_ACTIVE',
- 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
$tabId = \App\Module::getModuleId($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'tabid' => 'LBL_SOURCE_MODULE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Remove fields from dependent field entries.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldDepend->set('fields', $fields);
- 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 getCreateRecordUrl()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())->select(['id'])->from('s_#__fields_dependency')
- 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
continue;
- 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
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldDepend = \Settings_FieldsDependency_Record_Model::getInstanceById($fieldDependId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== ($key = array_search($fieldName, $fields))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($fields)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get Supported modules for fields dependency.
- 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 static function removeField(string $moduleName, string $fieldName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'views' => 'LBL_VIEWS',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = \App\Json::decode($fieldDepend->get('fields'));
- 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 Vtiger_Module_Model::getAll([0, 2], [], true);
- 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
$baseModuleName = \App\Module::getModuleName($fieldDepend->get('tabid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($baseModuleName === $moduleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldDepend->delete();
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldDepend->set('conditions', $conditions);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $listFields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'FieldsDependency';
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
->orWhere(['and', ['tabid' => $tabId], ['or', ['like', 'fields', "\"{$fieldName}\""], ['like', 'conditionsFields', "\"{$fieldName}\""]]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($fieldDependId = $dataReader->readColumn(0)) {
- 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
'mandatory' => 'LBL_MANDATORY',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'index.php?parent=Settings&module=FieldsDependency&view=List';
- 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
'fields' => 'LBL_FIELDS',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 'index.php?parent=Settings&module=FieldsDependency&view=Edit';
- 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
* @param string $fieldName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions = \App\Condition::removeFieldFromCondition($baseModuleName, $conditions, $moduleName, $fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'gui' => 'LBL_GUI',
- 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
->orWhere(['and', ['tabid' => $tabId], ['or', ['like', 'fields', "\"{$fieldName}\""], ['like', 'conditionsFields', "\"{$fieldName}\""]]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Settings_FieldsDependency_Module_Model" is not in camel caps format Open
class Settings_FieldsDependency_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks