Method process
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
$html = '';
$relationModuleName = 'Products';
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
Function process
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
$html = '';
$relationModuleName = 'Products';
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
- 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 using static access to class '\App\Fields\Double' in method 'process'. Open
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyPerUnit, false) . '</td>';
- 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 '\CurrencyField' in method 'process'. Open
<td style="font-size:9px;border:1px solid #ddd;background:#eee;"><b>' . \CurrencyField::convertToUserFormatSymbol($totalValue, true, $currencyInfo['currency_symbol']) . '<b></td>
- 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 'process'. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty/Unit', $relationModuleName) . '</th>';
- 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 '\CurrencyField' in method 'process'. Open
$html .= "<td style=\"{$bodyStyle}\">" . \CurrencyField::convertToUserFormatSymbol($value, true, $currencyInfo['currency_symbol']) . '</td>';
- 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 'process'. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $relationModuleName) . '</th>';
- 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 'process'. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty In Stock', $relationModuleName) . '</th>';
- 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 'process'. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('LBL_VALUE') . '</th>';
- 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_Record_Model' in method 'process'. Open
$entryRecordModel = \Vtiger_Record_Model::getInstanceById($entryId, $relationModuleName);
- 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\Double' in method 'process'. Open
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyInStock, false) . '</td>';
- 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_RelationListView_Model' in method 'process'. Open
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
- 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\Currency' in method 'process'. Open
$currencyInfo = \App\Fields\Currency::getDefault();
- 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 "" 4 times. Open
$html .= "<td style=\"{$bodyStyle}\">" . $entryRecordModel->getDisplayValue($header->getName()) . '</td>';
- 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 "" 4 times. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $relationModuleName) . '</th>';
- 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 deprecated function \Vtiger_Field_Model::getFieldLabel()
defined at /code/modules/Vtiger/models/Field.php:215
Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $relationModuleName) . '</th>';
- Exclude checks
Reference to instance property recordModel
from undeclared class \App\TextParser
Open
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
- Exclude checks
Call to undeclared method \Vtiger_Base_UIType::getValueForCurrency
Open
$unitPrice = $unitPriceUiTypeModel->getValueForCurrency($entryRecordModel->get($unitPriceField->getName()), $currencyId);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class IStorages_ProductsValueTable_Textparser extends \App\TextParser\Base
- Exclude checks
The class IStorages_ProductsValueTable_Textparser is not named in CamelCase. Open
class IStorages_ProductsValueTable_Textparser extends \App\TextParser\Base
{
/** @var string Class name */
public $name = 'LBL_PRODUCTS_VALUE_TABLE';
- 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 Class 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
foreach (['productname', 'ean', 'pscategory', 'unit_price'] as $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$fieldModel || !$fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('LBL_VALUE') . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var mixed Parser type */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entries = $relationListView->getAllEntries();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $productModel->getFieldByName($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$unitPrice = $unitPriceUiTypeModel->getValueForCurrency($entryRecordModel->get($unitPriceField->getName()), $currencyId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerStyle = 'font-size:9px;padding:0px 4px;text-align:center;';
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $relationModuleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty In Stock', $relationModuleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columns[$fieldName] = $fieldModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entryRecordModel = \Vtiger_Record_Model::getInstanceById($entryId, $relationModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$unitPriceUiTypeModel = $unitPriceField->getUITypeModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $type = 'pdf';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'LBL_PRODUCTS_VALUE_TABLE';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = '';
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$productModel = $relationListView->getRelatedModuleModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '<tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $qtyInStock * $unitPrice;
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$html .= '<table border="1" class="products-table" style="border-collapse:collapse;width:100%;"><thead><tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty/Unit', $relationModuleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</tr></thead><tbody>';
- 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
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $relationModuleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currencyInfo = \App\Fields\Currency::getDefault();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$currencyId = $currencyInfo['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$entryId = $entry->getId();
- 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
Line exceeds 120 characters; contains 137 characters Open
$unitPrice = $unitPriceUiTypeModel->getValueForCurrency($entryRecordModel->get($unitPriceField->getName()), $currencyId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($entries) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columns = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($entries as $entry) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qtyPerUnit = $entryRecordModel->get('qty_per_unit');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty/Unit', $relationModuleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bodyStyle = 'font-size:8px;border:1px solid #ddd;padding:0px 4px;';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$unitPriceField = $entryRecordModel->getField('unit_price');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalValue += $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relationModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '<table border="1" class="products-table" style="border-collapse:collapse;width:100%;"><thead><tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qtyInStock = $entryRecordModel->get('qtyinstock');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$totalValue = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationModuleName = 'Products';
- 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
Line exceeds 120 characters; contains 127 characters Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate('Qty In Stock', $relationModuleName) . '</th>';
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyPerUnit, false) . '</td>';
- 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
return $html;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyInStock, false) . '</td>';
- Exclude checks
Line exceeds 120 characters; contains 157 characters Open
$html .= "<td style=\"{$bodyStyle}\">" . \CurrencyField::convertToUserFormatSymbol($value, true, $currencyInfo['currency_symbol']) . '</td>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($columns as $header) {
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$html .= "<td style=\"{$bodyStyle}\">" . $entryRecordModel->getDisplayValue($header->getName()) . '</td>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '<tr style="background:#fff">
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<td style=\"{$bodyStyle}\">" . $entryRecordModel->getDisplayValue($header->getName()) . '</td>';
- 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
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyInStock, false) . '</td>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<td style=\"{$bodyStyle}\">" . \App\Fields\Double::formatToDisplay($qtyPerUnit, false) . '</td>';
- 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
$html .= '</tr>';
- Exclude checks
Line exceeds 120 characters; contains 206 characters Open
<td style="font-size:9px;border:1px solid #ddd;background:#eee;"><b>' . \CurrencyField::convertToUserFormatSymbol($totalValue, true, $currencyInfo['currency_symbol']) . '<b></td>
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<td style=\"{$bodyStyle}\">" . \CurrencyField::convertToUserFormatSymbol($value, true, $currencyInfo['currency_symbol']) . '</td>';
- Exclude checks
Class name "IStorages_ProductsValueTable_Textparser" is not in camel caps format Open
class IStorages_ProductsValueTable_Textparser extends \App\TextParser\Base
- Exclude checks