Function process
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
if ($request->isJSON()) {
$response = new Vtiger_Response();
$listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));
- 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 '51', column '52'). Open
foreach ($listViewModel->getListViewEntries(new Vtiger_Paging_Model()) as $recordModel) {
- 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 '48', column '20'). 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 '23', column '22'). Open
$pagingModel = new Vtiger_Paging_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
Avoid using static access to class '\App\Language' in method 'getBreadcrumbTitle'. Open
return \App\Language::translate('LBL_BUSINESS_HOURS', $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\Json' in method 'process'. Open
$response->setResult(\App\Json::encode($rows));
- 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_ListView_Model' in method 'process'. Open
$listViewModel = Settings_Vtiger_ListView_Model::getInstance($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
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 {
$viewer = $this->getViewer($request);
$this->initializeListViewContents($request, $viewer);
$viewer->view('ListViewContents.tpl', $request->getModule(false));
}
- 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_Vtiger_ListView_Model' in method 'initializeListViewContents'. Open
$listViewModel = Settings_Vtiger_ListView_Model::getInstance($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 unused local variables such as '$value'. Open
foreach ($data as $name => $value) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open
$this->listViewLinks = $listViewModel->getListViewLinks();
- Exclude checks
Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open
$viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('QUALIFIED_MODULE', $request->getModule(false));
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('PAGING_MODEL', $pagingModel);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('LISTVIEW_HEADERS', $this->listViewHeaders);
- Exclude checks
Reference to undeclared property \Settings_BusinessHours_List_View->listViewLinks
Open
if (!isset($this->listViewLinks)) {
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_MODEL', $module);
- Exclude checks
Assigning array
to property but \Settings_BusinessHours_List_View->listViewHeaders
is false
Open
$this->listViewHeaders = $listViewModel->getListViewHeaders();
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('COLUMN_NAME', '');
- Exclude checks
Assigning \Settings_Vtiger_Record_Model[]
to property but \Settings_BusinessHours_List_View->listViewEntries
is false
Open
$this->listViewEntries = $listViewModel->getListViewEntries($pagingModel);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('LISTVIEW_ENTRIES', $this->listViewEntries);
- Exclude checks
Argument 1 (var)
is false
but \count()
takes \Countable|array
Open
$viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View
- Exclude checks
The class Settings_BusinessHours_List_View is not named in CamelCase. Open
class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View
{
/** {@inheritdoc} */
public function getBreadcrumbTitle(App\Request $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
$pagingModel = new Vtiger_Paging_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->listViewLinks = $listViewModel->getListViewLinks();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->listViewHeaders) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset($this->listViewLinks)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->isJSON()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \App\Language::translate('LBL_BUSINESS_HOURS', $request->getModule(false));
- 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
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$module = $listViewModel->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
$viewer->view('ListViewContents.tpl', $request->getModule(false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- 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->initializeListViewContents($request, $viewer);
- 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 initializeListViewContents(App\Request $request, Vtiger_Viewer $viewer)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->listViewEntries = $listViewModel->getListViewEntries($pagingModel);
- 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('PAGING_MODEL', $pagingModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('LISTVIEW_ENTRIES_COUNT', \count($this->listViewEntries));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows[] = $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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult(\App\Json::encode($rows));
- 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
$data = $recordModel->getData();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getBreadcrumbTitle(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->listViewHeaders = $listViewModel->getListViewHeaders();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('LISTVIEW_LINKS', $this->listViewLinks);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('QUALIFIED_MODULE', $request->getModule(false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data[$name] = $recordModel->getDisplayValue($name);
- 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 (!$this->listViewEntries) {
- 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('COLUMN_NAME', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('LISTVIEW_HEADERS', $this->listViewHeaders);
- 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
$rows = [];
- 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 ($data as $name => $value) {
- 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
$viewer->assign('MODULE_MODEL', $module);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('LISTVIEW_ENTRIES', $this->listViewEntries);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($listViewModel->getListViewEntries(new Vtiger_Paging_Model()) as $recordModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$listViewModel = Settings_Vtiger_ListView_Model::getInstance($request->getModule(false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Settings_BusinessHours_List_View" is not in camel caps format Open
class Settings_BusinessHours_List_View extends Settings_Vtiger_List_View
- Exclude checks