Function process
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModuleName = $request->getModule(false);
$recordId = $request->get('record');
$roleName = $request->get('rolename');
- 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 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModuleName = $request->getModule(false);
$recordId = $request->get('record');
$roleName = $request->get('rolename');
The method process() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function process(App\Request $request)
{
$qualifiedModuleName = $request->getModule(false);
$recordId = $request->get('record');
$roleName = $request->get('rolename');
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '30', column '23'). Open
$recordModel = new Settings_Roles_Record_Model();
- 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
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 = new Settings_Roles_Record_Model();
}
- 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
Avoid using static access to class 'Settings_Roles_Record_Model' in method 'process'. Open
$parentRole = Settings_Roles_Record_Model::getInstanceById($parentRoleId);
- 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_Profiles_Record_Model' in method 'process'. Open
$profileRecordModel = Settings_Profiles_Record_Model::getInstanceById($profileId);
- 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_Roles_Record_Model' in method 'process'. Open
$recordModel = Settings_Roles_Record_Model::getInstanceById($recordId);
- 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_Vtiger_Module_Model' in method 'process'. Open
$moduleModel = Settings_Vtiger_Module_Model::getInstance($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
Call to undeclared method \Settings_Vtiger_Module_Model::getDefaultUrl
Open
header("location: {$moduleModel->getDefaultUrl()}");
- Exclude checks
Avoid excessively long variable names like $allowassignedrecordsto. Keep variable name length under 20. Open
$allowassignedrecordsto = $request->get('allowassignedrecordsto');
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks
The class Settings_Roles_Save_Action is not named in CamelCase. Open
class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action
{
/**
* Process.
*
- 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
->set('company', $request->getInteger('company'))
- 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 process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('rolename', $roleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header("location: {$moduleModel->getDefaultUrl()}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($allowassignedrecordsto)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($roleProfiles as $profileId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('listrelatedrecord', $request->getInteger('listRelatedRecord'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($recordModel && !empty($parentRoleId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} // set the value of assigned records to
- 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
->set('searchunpriv', $request->get('searchunpriv'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('globalsearchadv', $request->get('globalSearchAdvanced'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$roleName = $request->get('rolename');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allowassignedrecordsto = $request->get('allowassignedrecordsto');
- 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
->set('permissionsrelatedfield', $request->get('permissionsRelatedField'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$profileRecordModel->recalculate();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRole = Settings_Roles_Record_Model::getInstanceById($parentRoleId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('previewrelatedrecord', $request->getInteger('previewRelatedRecord'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('assignedmultiowner', $request->getInteger('assignedmultiowner'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$profileRecordModel = Settings_Profiles_Record_Model::getInstanceById($profileId);
- 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
* Process.
- 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
if (!empty($recordId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('clendarallorecords', $request->getInteger('clendarallorecords'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRole->addChildRole($recordModel);
- 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
$recordModel->set('allowassignedrecordsto', $allowassignedrecordsto);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($parentRole && !empty($roleName) && !empty($roleProfiles)) {
- 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
$recordId = $request->get('record');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($roleProfiles) {
- 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
$recordModel = new Settings_Roles_Record_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$roleProfiles = $request->get('profiles');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//After role updation recreating user privilege files
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRoleId = $request->getByType('parent_roleid', 2);
- 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_Roles_Record_Model::getInstanceById($recordId);
- 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
->set('auto_assign', $request->get('auto_assign'));
- 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
$moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('changeowner', $request->get('changeowner'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('editrelatedrecord', $request->get('editRelatedRecord'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('profileIds', $roleProfiles);
- Exclude checks
Class name "Settings_Roles_Save_Action" is not in camel caps format Open
class Settings_Roles_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks