YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/RecordAllocation/actions/SaveAjax.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method save has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function save(App\Request $request)
    {
        Settings_Vtiger_Tracker_Model::lockTracking(false);
        Settings_Vtiger_Tracker_Model::addBasic('save');
        $qualifiedModuleName = $request->getModule(false);
Severity: Minor
Found in modules/Settings/RecordAllocation/actions/SaveAjax.php - About 1 hr to fix

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

            $prevDetail['userId'] = implode(',', $oldValues);

    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 '$prevDetail' which will lead to PHP notices.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevDetail, $newDetail);

    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 '$newDetail' which will lead to PHP notices.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevDetail, $newDetail);

    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 '$newDetail' which will lead to PHP notices.
    Open

            $newDetail['userId'] = implode(',', $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

    Missing class import via use statement (line '45', column '25').
    Open

            $responceToEmit = 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 '65', column '25').
    Open

            $responceToEmit = 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_RecordAllocation_Module_Model' in method 'save'.
    Open

            $oldValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

    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 'Settings_RecordAllocation_Module_Model' in method 'save'.
    Open

            $newValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

    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 'removePanel'.
    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 'save'.
    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

    Avoid using static access to class 'Settings_Vtiger_Tracker_Model' in method 'removePanel'.
    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_Vtiger_Module_Model' in method 'save'.
    Open

            $moduleInstance = Settings_Vtiger_Module_Model::getInstance($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_Module_Model' in method 'removePanel'.
    Open

            $moduleInstance = Settings_Vtiger_Module_Model::getInstance($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_Tracker_Model' in method 'save'.
    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 'save'.
    Open

            Settings_Vtiger_Tracker_Model::addDetail($prevDetail, $newDetail);

    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_RecordAllocation_Module_Model' in method 'save'.
    Open

            Settings_RecordAllocation_Module_Model::resetDataVariable();

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

                'userid' => 'Integer',

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

                    'groups' => ['Integer'],

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

                'userid' => 'Integer',

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

                    'users' => ['Integer'],

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

                'module' => 'Alnum',

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

                'module' => 'Alnum',

    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 $newDetail was undeclared, but array fields are being added to it.
    Open

            $newDetail['userId'] = implode(',', $newValues);

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

            $prevDetail['userId'] = implode(',', $oldValues);

    Call to undeclared method \Settings_Vtiger_Module_Model::save
    Open

            $moduleInstance->save(array_filter($data));

    Avoid excessively long class names like Settings_RecordAllocation_SaveAjax_Action. Keep class name length under 40.
    Open

    class Settings_RecordAllocation_SaveAjax_Action extends Settings_Vtiger_Save_Action
    {
        public function __construct()
        {
            Settings_Vtiger_Tracker_Model::lockTracking();

    LongClassName

    Since: 2.9

    Detects when classes or interfaces are declared with excessively long names.

    Example

    class ATooLongClassNameThatHintsAtADesignProblem {
    
    }
    
    interface ATooLongInterfaceNameThatHintsAtADesignProblem {
    
    }

    Source https://phpmd.org/rules/naming.html#longclassname

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

    class Settings_RecordAllocation_SaveAjax_Action extends Settings_Vtiger_Save_Action

    The class Settings_RecordAllocation_SaveAjax_Action is not named in CamelCase.
    Open

    class Settings_RecordAllocation_SaveAjax_Action extends Settings_Vtiger_Save_Action
    {
        public function __construct()
        {
            Settings_Vtiger_Tracker_Model::lockTracking();

    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

            $oldValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

    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

                    'groups' => ['Integer'],

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

                ]

    Line exceeds 120 characters; contains 121 characters
    Open

            $newValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

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

        {

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

            $newDetail['userId'] = implode(',', $newValues);

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

            $responceToEmit->setResult(true);

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

        }

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

            $responceToEmit->setResult(true);

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

            $data = $request->getMultiDimensionArray('param', [

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

                'module' => 'Alnum',

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

            $moduleInstance->set('type', $data['type']);

    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

            $moduleInstance = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);

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

            Settings_Vtiger_Tracker_Model::addDetail($prevDetail, $newDetail);

    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

            $moduleName = $data['module'];

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

            $moduleInstance = Settings_Vtiger_Module_Model::getInstance($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

            Settings_Vtiger_Tracker_Model::lockTracking(false);

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

                'ids' => [

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

            $oldValues = array_merge((array) ($oldValues[$data['userid']]['users'] ?? []), (array) ($oldValues[$data['userid']]['groups'] ?? []));

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

            $newValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

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

                'module' => 'Alnum',

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

            $moduleInstance->set('type', $data['type']);

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

                'type' => 'Alnum',

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

                    'users' => ['Integer'],

    Line exceeds 120 characters; contains 121 characters
    Open

            $oldValues = Settings_RecordAllocation_Module_Model::getRecordAllocationByModule($data['type'], $data['module']);

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

        public function removePanel(App\Request $request)

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

            $responceToEmit->emit();

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

            $this->exposeMethod('save');

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

            Settings_RecordAllocation_Module_Model::resetDataVariable();

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

            $responceToEmit = new Vtiger_Response();

    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

            $this->exposeMethod('removePanel');

    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

                'userid' => 'Integer',

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

            $prevDetail['userId'] = implode(',', $oldValues);

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

    Line exceeds 120 characters; contains 142 characters
    Open

            $oldValues = array_merge((array) ($oldValues[$data['userid']]['users'] ?? []), (array) ($oldValues[$data['userid']]['groups'] ?? []));

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

            $data = $request->getMultiDimensionArray('param', [

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

            $newValues = array_merge((array) ($newValues[$data['userid']]['users'] ?? []), (array) ($newValues[$data['userid']]['groups'] ?? []));

    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

        {

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

                'type' => 'Alnum',

    Line exceeds 120 characters; contains 142 characters
    Open

            $newValues = array_merge((array) ($newValues[$data['userid']]['users'] ?? []), (array) ($newValues[$data['userid']]['groups'] ?? []));

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

        {

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

        public function save(App\Request $request)

    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

            $moduleInstance->save(array_filter($data));

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

            $responceToEmit->emit();

    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

            $moduleInstance->remove($moduleName);

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

            $responceToEmit = new Vtiger_Response();

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

    class Settings_RecordAllocation_SaveAjax_Action extends Settings_Vtiger_Save_Action

    There are no issues that match your filters.

    Category
    Status