Function process
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request, $widget = null)
{
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$data = $request->getAll();
- 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 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request, $widget = null)
{
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$data = $request->getAll();
The method process() has an NPath complexity of 216. The configured NPath complexity threshold is 200. Open
public function process(App\Request $request, $widget = null)
{
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$data = $request->getAll();
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method process() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function process(App\Request $request, $widget = null)
{
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$data = $request->getAll();
- 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
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
public function process(App\Request $request, $widget = null)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '33', column '30'). Open
$miniListWidgetModel = new Vtiger_MiniList_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 {
$widget->set('title', $miniListWidgetModel->getTitle());
$viewer->view('dashboards/MiniList.tpl', $moduleName);
}
- 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_WidgetsManagement_Module_Model' in method 'process'. Open
$owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);
- 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 {
$widgetId = $request->getInteger('widgetid');
}
- 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 '\App\User' in method 'process'. Open
$widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
- 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_Widget_Model' in method 'process'. Open
$widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
- 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 {
$owner = $request->getByType('owner', \App\Purifier::TEXT);
}
- 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 '\App\Json' in method 'process'. Open
$widgetParams = \App\Json::decode($widget->get('data'));
- 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 'process'. Open
$searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_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 'Vtiger_Field_Model' in method 'process'. Open
$filterField = Vtiger_Field_Model::getInstanceFromFieldId($widgetParams['filterFields']);
- 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 \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_NAME', $moduleName);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('WIDGET', $widget);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MINILIST_WIDGET_MODEL', $miniListWidgetModel);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('FILTER_FIELD', $filterField);
- Exclude checks
Call to method getInstanceWithWidgetId
from undeclared class \Vtiger_Widget_Model
Open
$widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('OWNER', $owner);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('FIELD_HREF', $fieldHref);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('SEARCH_DETAILS', $searchParams);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('DATA', $data);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('BASE_MODULE', $miniListWidgetModel->getTargetModule());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('SCRIPTS', $this->getFooterScripts($request));
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View
- Exclude checks
The class Vtiger_MiniList_Dashboard is not named in CamelCase. Open
class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View
{
public function process(App\Request $request, $widget = null)
{
$viewer = $this->getViewer($request);
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$request->has('owner')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgetId = $widget->get('id');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widget = Vtiger_Widget_Model::getInstanceWithWidgetId($widgetId, \App\User::getCurrentUserId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// Initialize Widget to the right-state of information
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request, $widget = null)
- 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
$widgetId = $request->getInteger('widgetid');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = $request->getAll();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($widget && !$request->has('widgetid')) {
- 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
$owner = Settings_WidgetsManagement_Module_Model::getDefaultUserId($widget);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldHref = $widgetParams['fieldHref'] ?? false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FIELD_HREF', $fieldHref);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has('content')) {
- 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 ($fieldListGroup as $fieldSearchInfo) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($widgetParams['filterFields'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$owner = $request->getByType('owner', \App\Purifier::TEXT);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$miniListWidgetModel->setWidgetModel($widget);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widgetParams = \App\Json::decode($widget->get('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
$fieldSearchInfo['searchValue'] = $fieldSearchInfo[2];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldSearchInfo['fieldName'] = $fieldName = $fieldSearchInfo[0];
- 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
$fieldSearchInfo['specialOption'] = \in_array($fieldSearchInfo[1], ['ch', 'kh']) ? 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
$viewer->assign('SEARCH_DETAILS', $searchParams);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$widget->set('title', $miniListWidgetModel->getTitle());
- 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 ($widget->get('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
$viewer->assign('MINILIST_WIDGET_MODEL', $miniListWidgetModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FILTER_FIELD', $filterField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('dashboards/MiniListContents.tpl', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($searchParams) && \is_array($searchParams)) {
- 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
$miniListWidgetModel->setSearchParams($searchParams);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($request->getArray('search_params') as $fieldListGroup) {
- 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
$viewer->assign('BASE_MODULE', $miniListWidgetModel->getTargetModule());
- 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
$viewer->assign('DATA', $data);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchParams[$fieldName] = $fieldSearchInfo;
- 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
$searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_params'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$filterField = Vtiger_Field_Model::getInstanceFromFieldId($widgetParams['filterFields']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('WIDGET', $widget);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('dashboards/MiniListFooter.tpl', $moduleName);
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$searchParams = App\Condition::validSearchParams($miniListWidgetModel->getTargetModule(), $request->getArray('search_params'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldHref = $filterField = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$miniListWidgetModel = new Vtiger_MiniList_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULE_NAME', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('OWNER', $owner);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('SCRIPTS', $this->getFooterScripts($request));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('dashboards/MiniList.tpl', $moduleName);
- Exclude checks
Class name "Vtiger_MiniList_Dashboard" is not in camel caps format Open
class Vtiger_MiniList_Dashboard extends Vtiger_IndexAjax_View
- Exclude checks