Method getListViewEntries
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getListViewEntries($pagingModel)
{
$module = $this->getModule();
$parentModuleName = $module->getParentName();
$qualifiedModuleName = 'PDF';
Function getListViewEntries
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getListViewEntries($pagingModel)
{
$module = $this->getModule();
$parentModuleName = $module->getParentName();
$qualifiedModuleName = 'PDF';
- 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 '27', column '17'). Open
$query = (new \App\Db\Query())->select($listFields)
- 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 '66', column '17'). Open
$query = (new \App\Db\Query())->from($module->baseTable);
- 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 'Vtiger_Loader' in method 'getListViewEntries'. Open
$recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $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
The method getListViewEntries uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$pagingModel->set('nextPageExists', 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 '\App\Language' in method 'getListViewEntries'. Open
$row['module_name'] = \App\Language::translate($row['module_name'], $row['module_name']);
- 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 'getListViewEntries'. Open
$row['summary'] = isset($row['summary']) ? \App\Language::translate($row['summary'], $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
Define a constant instead of duplicating this literal "summary" 3 times. Open
$row['summary'] = isset($row['summary']) ? \App\Language::translate($row['summary'], $qualifiedModuleName) : '';
- 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.
Define a constant instead of duplicating this literal "module_name" 5 times. Open
$query->where(['module_name' => $sourceModule]);
- 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.
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from($module->baseTable);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$query = (new \App\Db\Query())->select($listFields)
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_PDF_ListView_Model extends Settings_Vtiger_ListView_Model
- Exclude checks
The class Settings_PDF_ListView_Model is not named in CamelCase. Open
class Settings_PDF_ListView_Model extends Settings_Vtiger_ListView_Model
{
/** {@inheritdoc} */
public function getListViewEntries($pagingModel)
{
- 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 for alignment; tabs are not allowed Open
$module = $this->getModule();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!empty($parentModuleName)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!empty($sourceModule)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$orderBy = $this->getForSql('orderby');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$row['module_name'] = \App\Language::translate($row['module_name'], $row['module_name']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$pagingModel->calculatePageRange($dataReader->count());
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function getListViewCount()
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function getListViewEntries($pagingModel)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$listViewRecordModels = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$module = $this->getModule();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $listViewRecordModels;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query = (new \App\Db\Query())->select($listFields)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
array_pop($listViewRecordModels);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query = (new \App\Db\Query())->from($module->baseTable);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$sourceModule = $this->get('sourceModule');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$listFields[] = $module->baseIndex;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$startIndex = $pagingModel->getStartIndex();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query->where(['module_name' => $sourceModule]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$qualifiedModuleName = 'PDF';
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!empty($orderBy)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$listViewRecordModels[$record->getId()] = $record;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($dataReader->count() > $pageLimit) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$pagingModel->set('nextPageExists', true);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$pagingModel->set('nextPageExists', false);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $query->count();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$parentModuleName = $module->getParentName();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
->from($module->baseTable);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$sourceModule = $this->get('sourceModule');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$dataReader->close();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @author Radosław Skrzypczak <r.skrzypczak@yetiforce.com>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$dataReader = $query->limit($pageLimit + 1)->offset($startIndex)->createCommand()->query();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($sourceModule) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query->orderBy($orderBy . ' ' . $this->getForSql('sortorder'));
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$row['summary'] = isset($row['summary']) ? \App\Language::translate($row['summary'], $qualifiedModuleName) : '';
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$pageLimit = $pagingModel->getPageLimit();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$listFields = array_keys($module->listFields);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$record = new $recordModelClass();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$record->setData($row);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query->where(['module_name' => $sourceModule]);
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$row['summary'] = isset($row['summary']) ? \App\Language::translate($row['summary'], $qualifiedModuleName) : '';
- Exclude checks
Class name "Settings_PDF_ListView_Model" is not in camel caps format Open
class Settings_PDF_ListView_Model extends Settings_Vtiger_ListView_Model
- Exclude checks