Function setFilterPermissions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function setFilterPermissions(App\Request $request)
{
$user = $request->getByType('user', 'Text');
$add = $request->getBoolean('operator');
- 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 '106', column '19'). Open
$response = new Vtiger_Response();
- 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
Missing class import via use statement (line '69', column '19'). Open
$response = new Vtiger_Response();
- 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
Missing class import via use statement (line '33', column '19'). Open
$response = new Vtiger_Response();
- 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
Missing class import via use statement (line '99', column '15'). Open
throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED');
- 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
Missing class import via use statement (line '53', column '19'). Open
$response = new Vtiger_Response();
- 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\Language' in method 'upadteSequences'. Open
'message' => \App\Language::translate('LBL_SAVE_SEQUENCES', $request->getModule(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 '\App\Language' in method 'setFilterPermissions'. Open
$data['message'] = \App\Language::translate('LBL_SAVE_CONFIG', $request->getModule(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 '\App\Language' in method 'updateField'. Open
'message' => \App\Language::translate('Saving CustomView', $request->getModule(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 'CustomView_Record_Model' in method 'setFilterPermissions'. Open
$recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));
- 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 'delete'. Open
'message' => \App\Language::translate('Delete CustomView', $request->getModule(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 'Settings_CustomView_Module_Model' in method 'upadteSequences'. Open
Settings_CustomView_Module_Model::upadteSequences($params);
- 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 'CustomView_Record_Model' in method 'updateField'. Open
$recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));
- 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
Define a constant instead of duplicating this literal "message" 4 times. Open
'message' => \App\Language::translate('Delete CustomView', $request->getModule(false)),
- 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.
Remove the code after this "throw". Open
throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED');
- Read upRead up
- Exclude checks
Jump statements (return
, break
, continue
, and goto
) and throw
expressions move
control flow out of the current code block. Typically, any statements in a block that come after a jump or throw
are simply wasted
keystrokes lying in wait to confuse the unwary.
Rarely, as illustrated below, code after a jump or throw
is reachable. However, such code is difficult to understand, and should be
refactored.
Noncompliant Code Example
function fun($a) { $i = 10; return $i + $a; $i++; // this is never executed } function foo($a) { if ($a == 5) { goto error; } else { // do the job } return; error: printf("don't use 5"); // this is reachable but unreadable }
Compliant Solution
function fun($a) { $i = 10; return $i + $a; } function foo($a) { if ($a == 5) { handleError(); } else { // do the job } return; }
See
- MISRA C:2004, 14.1 - There shall be no unreachable code
- MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
- MISRA C++:2008, 0-1-9 - There shall be no dead code
- MISRA C:2012, 2.1 - A project shall not contain unreachable code
- MISRA C:2012, 2.2 - There shall be no dead code
- MITRE, CWE-561 - Dead Code
- CERT, MSC56-J. - Detect and remove superfluous code and values
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC07-CPP. - Detect and remove dead code
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action
- Exclude checks
The class Settings_CustomView_SaveAjax_Action is not named in CamelCase. Open
class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action
{
/**
* Constructor.
*/
- 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
parent::__construct();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->exposeMethod('setFilterPermissions');
- 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
$result = $add ? $recordModel->setDefaultForMember($user) : $recordModel->removeDefaultForMember($user);
- 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
$response->emit();
- 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
$response = new Vtiger_Response();
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$result = $add ? $recordModel->setFeaturedForMember($user) : $recordModel->removeFeaturedForMember($user);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Constructor.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Action to delete filter.
- 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
* Action to update sequences.
- 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 ($result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->emit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->exposeMethod('delete');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->exposeMethod('updateField');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = $request->getArray('param', 'Integer');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $add ? $recordModel->setFeaturedForMember($user) : $recordModel->removeFeaturedForMember($user);
- 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
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'success' => true,
- 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
public function setFilterPermissions(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
'message' => \App\Language::translate('Delete CustomView', $request->getModule(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
}
- 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 updateField(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- 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
* Action to set permissions.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$add = $request->getBoolean('operator');
- 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
$data['message'] = \App\Language::translate('LBL_SAVE_CONFIG', $request->getModule(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
Settings_CustomView_Module_Model::upadteSequences($params);
- 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
case 'featured':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => \App\Language::translate('Saving CustomView', $request->getModule(false)),
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => \App\Language::translate('LBL_SAVE_SEQUENCES', $request->getModule(false)),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($request->getByType('type')) {
- 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
$response = new Vtiger_Response();
- 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
public function delete(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('mode', 'edit');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->setValueFromRequest($request, $request->getByType('name', \App\Purifier::STANDARD), 'value');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult($data);
- 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
$response = new Vtiger_Response();
- 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
$user = $request->getByType('user', '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
*/
- 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
$response->emit();
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = ['success' => $result];
- 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
$this->exposeMethod('upadteSequences');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->emit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));
- 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
public function upadteSequences(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $add ? $recordModel->setPrivilegesForMember($user) : $recordModel->removePrivilegesForMember($user);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
CustomView_Record_Model::getInstanceById($request->getInteger('cvid'))->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
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'default':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Action to update parameter in the filter.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'permissions':
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$result = $add ? $recordModel->setPrivilegesForMember($user) : $recordModel->removePrivilegesForMember($user);
- Exclude checks
Class name "Settings_CustomView_SaveAjax_Action" is not in camel caps format Open
class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action
- Exclude checks