Method process
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModule = $request->getModule(false);
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
Function process
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
$qualifiedModule = $request->getModule(false);
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- 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 '74', column '60'). Open
$viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));
- 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 '53', column '13'). Open
$db = new \App\Db\Query();
- 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\Fields\Date' in method 'process'. Open
$date = \App\Fields\Date::formatToDB($request->getByType('duedate', 'DateInUserFormat'));
- 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 'vtlib\Functions' in method 'process'. Open
$dateCur = vtlib\Functions::getLastWorkingDay($dateCur);
- 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
$mainCurrencyInfo = \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
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 {
$dateCur = date('Y-m-d');
}
- 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\Log' in method 'process'. Open
\App\Log::trace('End ' . __METHOD__);
- 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_CurrencyUpdate_Module_Model' in method 'process'. Open
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- 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 "Y-m-d" 5 times. Open
if (strtotime($date) > strtotime(date('Y-m-d'))) {
- 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 "duedate" 3 times. Open
if (!$request->isEmpty('duedate')) {
- 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 \Vtiger_Viewer::assign
Open
$viewer->assign('MODULENAME', 'CurrencyUpdate');
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('CURRNUM', $curr_num);
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('BANK', $bankTab);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MAINCURR', $mainCurrencyInfo);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$db->from('yetiforce_currencyupdate_banks');
- Exclude checks
Call to method read
from undeclared class \yii\db\DataReader
Open
while ($row = $dataReader->read()) {
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- Exclude checks
Call to method close
from undeclared class \yii\db\DataReader
Open
$dataReader->close();
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('MODULE_MODEL', $moduleModel);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('HISTORIA', $history);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('UNSUPPORTED_CURRENCIES', $moduleModel->getUnSupportedCurrencies());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('SUPPORTED_CURRENCIES', $moduleModel->getSupportedCurrencies());
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_CurrencyUpdate_Index_View extends Settings_Vtiger_Index_View
- Exclude checks
The class Settings_CurrencyUpdate_Index_View is not named in CamelCase. Open
class Settings_CurrencyUpdate_Index_View extends Settings_Vtiger_Index_View
{
/**
* Process.
*
- 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
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = new \App\Db\Query();
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
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
$moduleModel->fetchCurrencyRates($dateCur);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$i;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULE_MODEL', $moduleModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel->refreshBanks();
- 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
$db->from('yetiforce_currencyupdate_banks');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$i = 0;
- 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
// get currency if not already archived
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// number of currencies
- 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
$qualifiedModule = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateCur = strtotime('-1 day', strtotime($dateCur));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateCur = vtlib\Functions::getLastWorkingDay($dateCur);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$history = $moduleModel->getRatesHistory($selectBankId, $dateCur, $request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankTab = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $db->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$downloadBtn = !$request->isEmpty('download') ? $request->getByType('download') : false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateCur = date('Y-m-d', $dateCur);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankTab[$i]['id'] = $row['id'];
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('SUPPORTED_CURRENCIES', $moduleModel->getSupportedCurrencies());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateCur = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = new \App\Db\Query();
- 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
$dateCur = '';
- 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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = \App\Fields\Date::formatToDB($request->getByType('duedate', 'DateInUserFormat'));
- 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
// take currency rates for yesterday
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankName = $row['bank_name'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MODULENAME', 'CurrencyUpdate');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// synchronise bank list
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (strtotime($date) > strtotime(date('Y-m-d'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 == strcmp(date('Y-m-d'), $dateCur)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankTab[$i]['active'] = $row['active'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// get info about main currency
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mainCurrencyInfo = \App\Fields\Currency::getDefault();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('BANK', $bankTab);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('Index.tpl', $qualifiedModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));
- 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
$date = date('Y-m-d');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$selectBankId = $moduleModel->getActiveBankId();
- 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
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('HISTORIA', $history);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('MAINCURR', $mainCurrencyInfo);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('CURRNUM', $curr_num);
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('UNSUPPORTED_CURRENCIES', $moduleModel->getUnSupportedCurrencies());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($downloadBtn) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bankTab[$i]['bank_name'] = $bankName;
- 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
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$request->isEmpty('duedate')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateCur = $date;
- 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
$curr_num = $moduleModel->getCurrencyNum();
- Exclude checks
Class name "Settings_CurrencyUpdate_Index_View" is not in camel caps format Open
class Settings_CurrencyUpdate_Index_View extends Settings_Vtiger_Index_View
- Exclude checks
The variable $curr_num is not named in camelCase. Open
public function process(App\Request $request)
{
$qualifiedModule = $request->getModule(false);
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $curr_num is not named in camelCase. Open
public function process(App\Request $request)
{
$qualifiedModule = $request->getModule(false);
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}