YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/SharingAccess/actions/IndexAjax.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method saveRule has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function saveRule(App\Request $request)
    {
        Settings_Vtiger_Tracker_Model::lockTracking(false);
        Settings_Vtiger_Tracker_Model::addBasic('save');
        $forModule = $request->getByType('for_module', 2);
Severity: Minor
Found in modules/Settings/SharingAccess/actions/IndexAjax.php - About 1 hr to fix

    Avoid using undefined variables such as '$prevValues' which will lead to PHP notices.
    Open

            $prevValues['permission'] = $ruleModel->getPermission();

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$newValues' which will lead to PHP notices.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevValues, $newValues);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$prevValues' which will lead to PHP notices.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevValues, $newValues);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$newValues' which will lead to PHP notices.
    Open

            $newValues['permission'] = $request->getInteger('permission');

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Missing class import via use statement (line '40', 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 '29', column '21').
    Open

                $ruleModel = new Settings_SharingAccess_Rule_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

    Missing class import via use statement (line '62', 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

    Avoid using static access to class 'Settings_Vtiger_Tracker_Model' in method 'saveRule'.
    Open

            Settings_Vtiger_Tracker_Model::lockTracking(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 '\App\Privilege' in method 'deleteRule'.
    Open

            \App\Privilege::setUpdater(\App\Module::getModuleName($forModule));

    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_Tracker_Model' in method 'saveRule'.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevValues, $newValues);

    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_Tracker_Model' in method 'deleteRule'.
    Open

            Settings_Vtiger_Tracker_Model::addBasic('delete');

    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_SharingAccess_Module_Model' in method 'deleteRule'.
    Open

            $moduleModel = Settings_SharingAccess_Module_Model::getInstance($forModule);

    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\Privilege' in method 'saveRule'.
    Open

            \App\Privilege::setUpdater($forModule);

    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_SharingAccess_Module_Model' in method 'saveRule'.
    Open

            $moduleModel = Settings_SharingAccess_Module_Model::getInstance($forModule);

    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_SharingAccess_Rule_Model' in method 'deleteRule'.
    Open

            $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $request->getInteger('record'));

    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_Tracker_Model' in method '__construct'.
    Open

            Settings_Vtiger_Tracker_Model::lockTracking();

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

            \App\Privilege::setUpdater(\App\Module::getModuleName($forModule));

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

                    'message' => \App\Language::translate('LBL_CUSTOM_RULE_SAVED_SUCCESSFULLY', $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 '\App\Language' in method 'saveRule'.
    Open

                $response->setError(\App\Language::translate('LBL_CUSTOM_RULE_SAVED_FAILED', $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_SharingAccess_Rule_Model' in method 'saveRule'.
    Open

                $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $request->getInteger('record'));

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

                $response->setError(\App\Language::translate('LBL_CUSTOM_RULE_DELETING_FAILED', $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

    The method saveRule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $request->getInteger('record'));
            }

    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_Tracker_Model' in method 'deleteRule'.
    Open

            Settings_Vtiger_Tracker_Model::lockTracking(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_Vtiger_Tracker_Model' in method 'saveRule'.
    Open

            Settings_Vtiger_Tracker_Model::addBasic('save');

    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 "record" 3 times.
    Open

            if ($request->isEmpty('record')) {

    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 "permission" 5 times.
    Open

            $prevValues['permission'] = $ruleModel->getPermission();

    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.

    Variable $newValues was undeclared, but array fields are being added to it.
    Open

            $newValues['permission'] = $request->getInteger('permission');

    Call to method delete on non-class type array
    Open

                $ruleModel->delete();

    Variable $prevValues was undeclared, but array fields are being added to it.
    Open

            $prevValues['permission'] = $ruleModel->getPermission();

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

    class Settings_SharingAccess_IndexAjax_Action extends Settings_Vtiger_Save_Action

    The class Settings_SharingAccess_IndexAjax_Action is not named in CamelCase.
    Open

    class Settings_SharingAccess_IndexAjax_Action extends Settings_Vtiger_Save_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

            $moduleModel = Settings_SharingAccess_Module_Model::getInstance($forModule);

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

            $newValues['permission'] = $request->getInteger('permission');

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

                $response->setError(\App\Language::translate('LBL_CUSTOM_RULE_DELETING_FAILED', $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

            Settings_Vtiger_Tracker_Model::addBasic('save');

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

            $ruleModel->set('target_id', $request->getByType('target_id', 'Text'));

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

                    'success' => true,

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

                $response->setError(\App\Language::translate('LBL_CUSTOM_RULE_SAVED_FAILED', $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

            $moduleModel = Settings_SharingAccess_Module_Model::getInstance($forModule);

    Line exceeds 120 characters; contains 121 characters
    Open

                $response->setError(\App\Language::translate('LBL_CUSTOM_RULE_DELETING_FAILED', $request->getModule(false)));

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

            if ($request->isEmpty('record')) {

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

            }

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

            $prevValues['permission'] = $ruleModel->getPermission();

    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

            }

    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

            $ruleModel->set('source_id', $request->getByType('source_id', 'Text'));

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

            } catch (\App\Exceptions\AppException $e) {

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

        {

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

            Settings_Vtiger_Tracker_Model::lockTracking();

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

            $ruleModel->set('permission', $request->getInteger('permission'));

    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

                $ruleModel = new Settings_SharingAccess_Rule_Model();

    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

                $ruleModel->save();

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

        public function saveRule(App\Request $request)

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

            Settings_Vtiger_Tracker_Model::lockTracking(false);

    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

            $response->emit();

    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

        {

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

            \App\Privilege::setUpdater(\App\Module::getModuleName($forModule));

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

            } catch (\App\Exceptions\AppException $e) {

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

                $ruleModel->setModuleFromInstance($moduleModel);

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

                $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $request->getInteger('record'));

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

        }

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

            $response->setEmitType(Vtiger_Response::$EMIT_JSON);

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

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

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

            Settings_Vtiger_Tracker_Model::addDetail($prevValues, $newValues);

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

                ]);

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

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

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

            $this->exposeMethod('saveRule');

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

            $this->exposeMethod('deleteRule');

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

        public function deleteRule(App\Request $request)

    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

            try {

    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

            \App\Privilege::setUpdater($forModule);

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

            $response->setEmitType(Vtiger_Response::$EMIT_JSON);

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

            Settings_Vtiger_Tracker_Model::lockTracking(false);

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

                $ruleModel->delete();

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

                $response->setResult([

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

                    'message' => \App\Language::translate('LBL_CUSTOM_RULE_SAVED_SUCCESSFULLY', $request->getModule(false))

    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

            Settings_Vtiger_Tracker_Model::addBasic('delete');

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

            $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $request->getInteger('record'));

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

    class Settings_SharingAccess_IndexAjax_Action extends Settings_Vtiger_Save_Action

    There are no issues that match your filters.

    Category
    Status