YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Vtiger/actions/TaxAjax.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

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

    public function process(App\Request $request)
    {
        $mode = $request->getMode();
        if (!empty($mode)) {
            echo $this->invokeExposedMethod($mode, $request);
Severity: Minor
Found in modules/Settings/Vtiger/actions/TaxAjax.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $mode = $request->getMode();
            if (!empty($mode)) {
                echo $this->invokeExposedMethod($mode, $request);
    Severity: Minor
    Found in modules/Settings/Vtiger/actions/TaxAjax.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 '47', column '19').
    Open

            $response = new Vtiger_Response();

    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 '73', column '19').
    Open

            $response = new Vtiger_Response();

    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 '33', column '26').
    Open

                $taxRecordModel = new Settings_Vtiger_TaxRecord_Model();

    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 'Settings_Vtiger_TaxRecord_Model' in method 'checkDuplicateName'.
    Open

            $exists = Settings_Vtiger_TaxRecord_Model::checkDuplicate($taxLabel, $taxId, $type);

    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 {
                $taxRecordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);
            }

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

                $recordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

    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 checkDuplicateName uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $result = ['success' => true, 'message' => \App\Language::translate('LBL_TAX_NAME_EXIST', $qualifiedModuleName)];
            }

    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\Language' in method 'checkDuplicateName'.
    Open

                $result = ['success' => true, 'message' => \App\Language::translate('LBL_TAX_NAME_EXIST', $qualifiedModuleName)];

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

                $taxRecordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

    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

    Call to method checkDuplicate from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

            $exists = Settings_Vtiger_TaxRecord_Model::checkDuplicate($taxLabel, $taxId, $type);

    Suspicious argument \App\Controller\type for an echo/print statement
    Open

                echo $this->invokeExposedMethod($mode, $request);

    Call to method __construct from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

                $taxRecordModel = new Settings_Vtiger_TaxRecord_Model();

    Call to method set from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

                    $taxRecordModel->set($fieldName, $request->get($fieldName));

    Call to method getInstanceById from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

                $recordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

    Call to method getCurrentUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                $response->setResult(array_merge(['_editurl' => $recordModel->getEditTaxUrl(), 'type' => $recordModel->getType(), 'row_type' => \App\User::getCurrentUserModel()->getDetail('rowheight')], $recordModel->getData()));

    Call to method getInstanceById from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

                $taxRecordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

    Call to method setType from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

            $taxRecordModel->setType($type);

    Call to method save from undeclared class \Settings_Vtiger_TaxRecord_Model
    Open

                $taxId = $taxRecordModel->save();

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

    class Settings_Vtiger_TaxAjax_Action extends Settings_Vtiger_Basic_Action

    The class Settings_Vtiger_TaxAjax_Action is not named in CamelCase.
    Open

    class Settings_Vtiger_TaxAjax_Action extends Settings_Vtiger_Basic_Action
    {
        use \App\Controller\ExposeMethod;
    
        public function __construct()

    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

                $taxId = $taxRecordModel->save();

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

        public function checkDuplicateName(App\Request $request)

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

            $taxId = $request->get('taxid');

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

            if (!$exists) {

    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($taxId)) {

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

                $taxRecordModel = new Settings_Vtiger_TaxRecord_Model();

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

                if ($request->has($fieldName)) {

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

                $response->setError($e->getCode(), $e->getMessage());

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

        public function __construct()

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

                $response->setResult(array_merge(['_editurl' => $recordModel->getEditTaxUrl(), 'type' => $recordModel->getType(), 'row_type' => \App\User::getCurrentUserModel()->getDetail('rowheight')], $recordModel->getData()));

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

            $response->emit();

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

        }

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

        use \App\Controller\ExposeMethod;

    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

            $taxId = $request->get('taxid');

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

            $exists = Settings_Vtiger_TaxRecord_Model::checkDuplicate($taxLabel, $taxId, $type);

    Line exceeds 120 characters; contains 125 characters
    Open

                $result = ['success' => true, 'message' => \App\Language::translate('LBL_TAX_NAME_EXIST', $qualifiedModuleName)];

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

            }

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

            $fields = ['taxlabel', 'percentage', 'deleted'];

    Line exceeds 120 characters; contains 225 characters
    Open

                $response->setResult(array_merge(['_editurl' => $recordModel->getEditTaxUrl(), 'type' => $recordModel->getType(), 'row_type' => \App\User::getCurrentUserModel()->getDetail('rowheight')], $recordModel->getData()));

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

            $mode = $request->getMode();

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

            $taxLabel = $request->get('taxlabel');

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

            foreach ($fields as $fieldName) {

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

            $response = new Vtiger_Response();

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

            if (!empty($mode)) {

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

            }

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

            $type = $request->get('type');

    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

                    $taxRecordModel->set($fieldName, $request->get($fieldName));

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

            $response = new Vtiger_Response();

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

                $recordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

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

            } catch (Exception $e) {

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

            $response->setResult($result);

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

            parent::__construct();

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

            $this->exposeMethod('checkDuplicateName');

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

                $taxRecordModel = Settings_Vtiger_TaxRecord_Model::getInstanceById($taxId, $type);

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

            $taxRecordModel->setType($type);

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

            try {

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

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

    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

            }

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

                $result = ['success' => false];

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

            $type = $request->get('type');

    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

            }

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

        {

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

                $result = ['success' => true, 'message' => \App\Language::translate('LBL_TAX_NAME_EXIST', $qualifiedModuleName)];

    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

                return;

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

            $response->emit();

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

                echo $this->invokeExposedMethod($mode, $request);

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

        }

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

    class Settings_Vtiger_TaxAjax_Action extends Settings_Vtiger_Basic_Action

    There are no issues that match your filters.

    Category
    Status