Function process
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModuleName = $request->getModule(false);
if (!$request->isEmpty('record', true)) {
$recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
- 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
Method process
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModuleName = $request->getModule(false);
if (!$request->isEmpty('record', true)) {
$recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
Avoid using static access to class 'Settings_TreesManager_Record_Model' in method 'process'. Open
$recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);
- 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_TreesManager_Record_Model' in method 'process'. Open
$recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
- 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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);
}
- 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
Call with 1 arg(s) to \Settings_TreesManager_Record_Model::getCleanInstance()
which only takes 0 arg(s) defined at /code/modules/Settings/TreesManager/models/Record.php:407
Open
$recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks
The class Settings_TreesManager_Save_Action is not named in CamelCase. Open
class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action
{
/**
* Save tree.
*
- 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
if ($request->has($fieldName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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 \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
header('location: ' . $recordModel->getModule()->getListViewUrl());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('replace', $request->getMultiDimensionArray('replace', [['old' => ['Integer'], ['new' => ['Integer']]]]));
- 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
$fieldModel = $recordModel->getFieldInstanceByName($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldUITypeModel->validate($value, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Save tree.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel->isEditableReadOnly()) {
- 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
switch ($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
case 'tree':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $recordModel->parseTreeDataForSave($tree);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $request->getArray($fieldName, \App\Purifier::INTEGER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tree = $request->getArray('tree', 'Text');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($fieldName, $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
if (!$request->isEmpty('record', true)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields['tree'] = 'tree';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $request->getByType($fieldName, $fieldModel->get('purifyType'));
- 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
$qualifiedModuleName = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldUITypeModel = $fieldModel->getUITypeModel();
- 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 = array_intersect($value, array_keys($fieldModel->getPicklistValues()));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Settings_TreesManager_Record_Model::getCleanInstance($qualifiedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $fieldModel->getDBValue($value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$recordModel->set('replace', $request->getMultiDimensionArray('replace', [['old' => ['Integer'], ['new' => ['Integer']]]]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'share':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->save();
- 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 = $recordModel->editFields;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- 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
$recordModel = Settings_TreesManager_Record_Model::getInstanceById($request->getInteger('record'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Settings_TreesManager_Save_Action" is not in camel caps format Open
class Settings_TreesManager_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks