Function getSearchParams
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getSearchParams($stage, $assignedto, $dates)
{
$listSearchParams = [];
$conditions = [];
array_push($conditions, ['sales_stage', 'e', $stage]);
- 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
Avoid unused parameters such as '$request'. Open
public function getHeaderCss(App\Request $request)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_NAME', $moduleName);
- Exclude checks
Call to method getGroupName
from undeclared class \App\Fields\Owner
Open
$groupName = \App\Fields\Owner::getGroupName($assignedto);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('WIDGET', $widget);
- Exclude checks
Call to method getUserLabel
from undeclared class \App\Fields\Owner
Open
array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);
- Exclude checks
Call to method getInstance
from undeclared class \Vtiger_Widget_Model
Open
$widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$currentUserId = \App\User::getCurrentUserId();
- Exclude checks
Call to undeclared method \Vtiger_Module_Model::getProjectWidget
Open
$data = $moduleModel->getProjectWidget($owner, $dates);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('STYLES', $this->getHeaderCss($request));
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('CURRENTUSER', $currentUserId);
- Exclude checks
Saw unextractable annotation for comment '* @return <array> - array of Vtiger_CssScript_Model'</array>
Open
* @return <array> - array of Vtiger_CssScript_Model
- Exclude checks
Call to method getType
from undeclared class \App\Fields\Owner
Open
$ownerType = \App\Fields\Owner::getType($assignedto);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('DATA', $data);
- Exclude checks
Avoid using static access to class 'Users_Record_Model' in method 'getSearchParams'. Open
$currenUserModel = Users_Record_Model::getCurrentUserModel();
- 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\User' in method 'process'. Open
$currentUserId = \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::getInstance($request->getInteger('linkid'), $currentUserId);
- 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_WidgetsManagement_Module_Model' in method 'process'. Open
$dates = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($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
Avoid using static access to class '\App\Fields\Owner' in method 'getSearchParams'. Open
$groupName = \App\Fields\Owner::getGroupName($assignedto);
- 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 'process'. Open
$moduleModel = Vtiger_Module_Model::getInstance($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 '\App\Fields\Owner' in method 'getSearchParams'. Open
$ownerType = \App\Fields\Owner::getType($assignedto);
- 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\Fields\Date' in method 'process'. Open
$dates = \App\Fields\Date::formatRangeToDisplay($dates);
- 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 getSearchParams uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$groupName = \App\Fields\Owner::getGroupName($assignedto);
array_push($conditions, ['assigned_user_id', 'e', $groupName]);
}
- 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\Fields\Owner' in method 'getSearchParams'. Open
array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View
- Exclude checks
The class Project_ProjectWidget_Dashboard is not named in CamelCase. Open
class Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View
{
/**
* Retrieves css styles that need to loaded in the page.
*
- 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
$groupName = \App\Fields\Owner::getGroupName($assignedto);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_push($conditions, ['assigned_user_id', 'e', $groupName]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$owner = $request->getByType('owner', 2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHeaderCss(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
array_push($conditions, ['assigned_user_id', 'e', \App\Fields\Owner::getUserLabel($assignedto)]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = $moduleModel->getProjectWidget($owner, $dates);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data[$i][] = $listViewUrl . $this->getSearchParams($data[$i][0], $owner, $dates);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_push($conditions, ['closingdate', 'bw', implode(',', $dates)]);
- 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
//Include special script and css needed for this widget
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('all' != $assignedto) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($dates)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = Settings_WidgetsManagement_Module_Model::getDefaultDateRange($widget);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
- 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
//Place your widget specific css files here
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('' == $assignedto) {
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listViewUrl = $moduleModel->getListViewUrl();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$countData = \count($data);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
for ($i = 0; $i < $countData; ++$i) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('dashboards/CampaignsWidget.tpl', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->checkAndConvertCssStyles([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ownerType = \App\Fields\Owner::getType($assignedto);
- 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
$listSearchParams[] = $conditions;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currentUserId = \App\User::getCurrentUserId();
- 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
$listSearchParams = [];
- 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
$widget = Vtiger_Widget_Model::getInstance($request->getInteger('linkid'), $currentUserId);
- 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('CURRENTUSER', $currentUserId);
- 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 getSearchParams($stage, $assignedto, $dates)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dates = \App\Fields\Date::formatRangeToDisplay($dates);
- 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
$viewer->assign('WIDGET', $widget);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Retrieves css styles that need to loaded in the page.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('STYLES', $this->getHeaderCss($request));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return <array> - array of Vtiger_CssScript_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currenUserModel = Users_Record_Model::getCurrentUserModel();
- 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
* @param \App\Request $request - request model
- 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 ('Users' == $ownerType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '&search_params=' . json_encode($listSearchParams);
- 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
$dates = $request->getDateRange('expectedclosedate');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$assignedto = $currenUserModel->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($dates)) {
- 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
$conditions = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
array_push($conditions, ['sales_stage', 'e', $stage]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('DATA', $data);
- Exclude checks
Class name "Project_ProjectWidget_Dashboard" is not in camel caps format Open
class Project_ProjectWidget_Dashboard extends Vtiger_IndexAjax_View
- Exclude checks