YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/RecordNumbering/views/Advanced.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method process has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $supportedModules = Settings_RecordNumbering_Module_Model::getSupportedModules();
        $sourceModule = $request->getByType('sourceModule', 2);
        $valueParam = $request->getByType('picklist', \App\Purifier::TEXT);
Severity: Minor
Found in modules/Settings/RecordNumbering/views/Advanced.php - About 1 hr to fix

    Function process has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function process(App\Request $request)
        {
            $supportedModules = Settings_RecordNumbering_Module_Model::getSupportedModules();
            $sourceModule = $request->getByType('sourceModule', 2);
            $valueParam = $request->getByType('picklist', \App\Purifier::TEXT);
    Severity: Minor
    Found in modules/Settings/RecordNumbering/views/Advanced.php - About 1 hr 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 '29', column '26').
    Open

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

    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\Picklist' in method 'process'.
    Open

                foreach (\App\Fields\Picklist::getValues($picklistName[1]) as $value) {

    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\TextParser' in method 'process'.
    Open

            if (!empty($picklistName[1]) && !\App\TextParser::isVaribleToParse($valueParam) && $moduleModel->getFieldByName($picklistName[1])) {

    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\Module' in method 'process'.
    Open

                $defaultModuleModel = $supportedModules[\App\Module::getModuleId($sourceModule)];

    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 'preProcessAjax'.
    Open

            $this->pageTitle = \App\Language::translate('LBL_ADVANCED_RECORD_NUMBERING', $request->getModule(false));

    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_RecordNumbering_Module_Model' in method 'process'.
    Open

            $supportedModules = Settings_RecordNumbering_Module_Model::getSupportedModules();

    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_Module_Model' in method 'process'.
    Open

            $moduleModel = \Vtiger_Module_Model::getInstance($sourceModule);

    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 {
                $defaultModuleModel = reset($supportedModules);
            }

    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

    Define a constant instead of duplicating this literal "cur_id" 3 times.
    Open

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

    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 "prefix" 4 times.
    Open

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

    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 method isVaribleToParse from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
    Open

            if (!empty($picklistName[1]) && !\App\TextParser::isVaribleToParse($valueParam) && $moduleModel->getFieldByName($picklistName[1])) {

    Reference to undeclared property \Settings_RecordNumbering_Advanced_View->dangerBtn
    Open

                $this->dangerBtn = '';

    Reference to undeclared property \Settings_RecordNumbering_Advanced_View->successBtn
    Open

                $this->successBtn = '';

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

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

    Static call to undeclared method \App\Controller\ModalSettings::preProcessAjax
    Open

            parent::preProcessAjax($request);

    Reference to undeclared property \Settings_RecordNumbering_Advanced_View->pageTitle
    Open

            $this->pageTitle = \App\Language::translate('LBL_ADVANCED_RECORD_NUMBERING', $request->getModule(false));

    Call to undeclared method \Settings_RecordNumbering_Advanced_View::getViewer
    Open

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

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class Settings_RecordNumbering_Advanced_View extends \App\Controller\ModalSettings

    The class Settings_RecordNumbering_Advanced_View is not named in CamelCase.
    Open

    class Settings_RecordNumbering_Advanced_View extends \App\Controller\ModalSettings
    {
        /** {@inheritdoc} */
        public function preProcessAjax(App\Request $request)
        {

    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

            $sourceModule = $request->getByType('sourceModule', 2);

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

                $defaultModuleModel = $supportedModules[\App\Module::getModuleId($sourceModule)];

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

                $valueSequences = [];

    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

            $viewer->assign('SUPPORTED_MODULES', $supportedModules);

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

        }

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

                $defaultModuleModel = reset($supportedModules);

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

            $valueParam = $request->getByType('picklist', \App\Purifier::TEXT);

    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

                    if (!empty($value['prefix'])) {

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

                }

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

            $viewer->assign('PICKLISTS_VALUES', $valueSequences);

    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 = \Vtiger_Module_Model::getInstance($sourceModule);

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

            if ($sourceModule) {

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

            if (!empty($picklistName[1]) && !\App\TextParser::isVaribleToParse($valueParam) && $moduleModel->getFieldByName($picklistName[1])) {

    Line exceeds 120 characters; contains 140 characters
    Open

            if (!empty($picklistName[1]) && !\App\TextParser::isVaribleToParse($valueParam) && $moduleModel->getFieldByName($picklistName[1])) {

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

        /** {@inheritdoc} */

    Line exceeds 120 characters; contains 173 characters
    Open

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

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

        }

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

            $supportedModules = Settings_RecordNumbering_Module_Model::getSupportedModules();

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

            $valueSequences = (new \App\Db\Query())->select(['prefix' => 'value', 'cur_id'])->from('u_#__modentity_sequences')->where(['tabid' => $moduleModel->getId()])->all();

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

                $currentValues = array_column($valueSequences, 'cur_id', 'prefix');

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

                        $value['cur_id'] = $currentValues[$value['prefix']] ?? 1;

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

            }

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

            if (empty($valueSequences)) {

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

            $viewer->view('Advanced.tpl', $request->getModule(false));

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

        public function preProcessAjax(App\Request $request)

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

            preg_match('/{{picklist:([a-z0-9_]+)}}/i', $valueParam, $picklistName);

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

        {

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

                        $valueSequences[] = $value;

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

            }

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

            $this->pageTitle = \App\Language::translate('LBL_ADVANCED_RECORD_NUMBERING', $request->getModule(false));

    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

            }

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

                    }

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

                $this->dangerBtn = '';

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

            parent::preProcessAjax($request);

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

        /** {@inheritdoc} */

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

                foreach (\App\Fields\Picklist::getValues($picklistName[1]) as $value) {

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

                $this->successBtn = '';

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

            $viewer->assign('DEFAULT_MODULE_MODEL', $defaultModuleModel);

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

    class Settings_RecordNumbering_Advanced_View extends \App\Controller\ModalSettings

    There are no issues that match your filters.

    Category
    Status