YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/CurrencyUpdate/views/Index.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

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();

Severity: Major
Found in modules/Settings/CurrencyUpdate/views/Index.php - About 2 hrs to fix

    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();
    
    
    Severity: Minor
    Found in modules/Settings/CurrencyUpdate/views/Index.php - About 35 mins to fix

    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) : ''));

    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();

    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'));

    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);

    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();

    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');
            }

    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__);

    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();

    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'))) {

    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')) {

    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');

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('CURRNUM', $curr_num);

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('End ' . __METHOD__);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('BANK', $bankTab);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('MAINCURR', $mainCurrencyInfo);

    Call to undeclared method \App\Db\Query::from
    Open

            $db->from('yetiforce_currencyupdate_banks');

    Call to method read from undeclared class \yii\db\DataReader
    Open

            while ($row = $dataReader->read()) {

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);

    Call to method close from undeclared class \yii\db\DataReader
    Open

            $dataReader->close();

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('MODULE_MODEL', $moduleModel);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('HISTORIA', $history);

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('UNSUPPORTED_CURRENCIES', $moduleModel->getUnSupportedCurrencies());

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('SUPPORTED_CURRENCIES', $moduleModel->getSupportedCurrencies());

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));

    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

    The class Settings_CurrencyUpdate_Index_View is not named in CamelCase.
    Open

    class Settings_CurrencyUpdate_Index_View extends Settings_Vtiger_Index_View
    {
        /**
         * Process.
         *

    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();

    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;

    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

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $moduleModel->fetchCurrencyRates($dateCur);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ++$i;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('MODULE_MODEL', $moduleModel);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $moduleModel->refreshBanks();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $db->from('yetiforce_currencyupdate_banks');

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $i = 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            while ($row = $dataReader->read()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // get currency if not already archived

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // number of currencies

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer = $this->getViewer($request);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $qualifiedModule = $request->getModule(false);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dateCur = strtotime('-1 day', strtotime($dateCur));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $dateCur = vtlib\Functions::getLastWorkingDay($dateCur);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $history = $moduleModel->getRatesHistory($selectBankId, $dateCur, $request);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $bankTab = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $dataReader = $db->createCommand()->query();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $downloadBtn = !$request->isEmpty('download') ? $request->getByType('download') : false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dateCur = date('Y-m-d', $dateCur);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $bankTab[$i]['id'] = $row['id'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('SUPPORTED_CURRENCIES', $moduleModel->getSupportedCurrencies());

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dateCur = date('Y-m-d');

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $db = new \App\Db\Query();

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $dateCur = '';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param \App\Request $request

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $date = \App\Fields\Date::formatToDB($request->getByType('duedate', 'DateInUserFormat'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // take currency rates for yesterday

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $bankName = $row['bank_name'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('MODULENAME', 'CurrencyUpdate');

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // synchronise bank list

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if (strtotime($date) > strtotime(date('Y-m-d'))) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (0 == strcmp(date('Y-m-d'), $dateCur)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $bankTab[$i]['active'] = $row['active'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            // get info about main currency

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $mainCurrencyInfo = \App\Fields\Currency::getDefault();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('BANK', $bankTab);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->view('Index.tpl', $qualifiedModule);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $date = date('Y-m-d');

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $selectBankId = $moduleModel->getActiveBankId();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $dataReader->close();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            \App\Log::trace('End ' . __METHOD__);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('HISTORIA', $history);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('MAINCURR', $mainCurrencyInfo);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('CURRNUM', $curr_num);

    Line exceeds 120 characters; contains 121 characters
    Open

            $viewer->assign('DATE', ($request->has('duedate') ? (new Vtiger_Date_UIType())->getDisplayValue($dateCur) : ''));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $viewer->assign('UNSUPPORTED_CURRENCIES', $moduleModel->getUnSupportedCurrencies());

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($downloadBtn) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $bankTab[$i]['bank_name'] = $bankName;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Process.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process(App\Request $request)

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!$request->isEmpty('duedate')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dateCur = $date;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $curr_num = $moduleModel->getCurrencyNum();

    Class name "Settings_CurrencyUpdate_Index_View" is not in camel caps format
    Open

    class Settings_CurrencyUpdate_Index_View extends Settings_Vtiger_Index_View

    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();
    
    

    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();
    
    

    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

    There are no issues that match your filters.

    Category
    Status