Function getEntries
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function getEntries(): array
{
$entries = [];
$addInventoryData = $this->fullData && $this->moduleInstance->isInventory();
if ($addInventoryData) {
- 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 getEntries
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getEntries(): array
{
$entries = [];
$addInventoryData = $this->fullData && $this->moduleInstance->isInventory();
if ($addInventoryData) {
Missing class import via use statement (line '52', column '18'). Open
$rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
- 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_Inventory_Model' in method 'getEntries'. Open
$inventoryModel = Vtiger_Inventory_Model::getInstance($this->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
The method getEntries uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$entries[] = $sanitizedRow;
}
- 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
The method getEntries uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$entries[] = $sanitizedRow;
}
- 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
Call to method close
from undeclared class \yii\db\DataReader
Open
$dataReader->close();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
- Exclude checks
Call to method read
from undeclared class \yii\db\DataReader
Open
while ($row = $dataReader->read()) {
- Exclude checks
Avoid excessively long variable names like $sanitizedInventoryRow. Keep variable name length under 20. Open
$sanitizedInventoryRow = $this->sanitizeInventoryValues($row, $inventoryFields);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_ExportToCsv_Model extends \App\Export\Records
- Exclude checks
The class Vtiger_ExportToCsv_Model is not named in CamelCase. Open
class Vtiger_ExportToCsv_Model extends \App\Export\Records
{
/** @var string File extension. */
protected $fileExtension = 'csv';
- 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
/** @var string File extension. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rowsCounter = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entries[] = $sanitizedRow;
- 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
return $entries;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function that create the exported file.
- 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
* Function exports the data based on the mode.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->output($this->getHeaders(), $this->getEntries());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- 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
$output = fopen('php://output', 'w');
- 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 array $entries - output file data
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
fputcsv($output, $headers);
- 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
$dataReader = $this->getExportQuery()->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($addInventoryData) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sanitizedRow[] = $rowsCounter++;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($rows as &$row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- 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
fputcsv($output, $row);
- 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
$inventoryFields = $inventoryModel->getFields();
- 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
$inventoryTable = $inventoryModel->getDataTableName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($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
public function getEntries(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entries[] = $sanitizedRow;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function output(array $headers, array $entries)
- 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
$entries = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get entires.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
- 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
protected $fileExtension = 'csv';
- 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
if ($addInventoryData) {
- 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 array $headers - output file header
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
fclose($output);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows = (new \App\Db\Query())->from($inventoryTable)->where(['crmid' => $row['id']])->orderBy('seq')->all();
- 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 exportData(): void
- 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
$inventoryModel = Vtiger_Inventory_Model::getInstance($this->moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sanitizedInventoryRow = $this->sanitizeInventoryValues($row, $inventoryFields);
- 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
$addInventoryData = $this->fullData && $this->moduleInstance->isInventory();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- 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
$entries[] = array_merge($sanitizedRow, $sanitizedInventoryRow);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sanitizedRow = $this->sanitizeValues($row);
- 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 ($entries as $row) {
- Exclude checks
Class name "Vtiger_ExportToCsv_Model" is not in camel caps format Open
class Vtiger_ExportToCsv_Model extends \App\Export\Records
- Exclude checks