YetiForceCompany/YetiForceCRM

View on GitHub
modules/Users/actions/MassSave.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Function getRecordModelsFromRequest has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function getRecordModelsFromRequest(App\Request $request)
    {
        $moduleName = $request->getModule();
        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
        $recordIds = self::getRecordsListFromRequest($request);
Severity: Minor
Found in modules/Users/actions/MassSave.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 '34', column '19').
Open

        $response = new Vtiger_Response();
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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 '52', column '22').
Open

            $recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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 'Users_Record_Model' in method 'checkPermission'.
Open

        $currentUserModel = Users_Record_Model::getCurrentUserModel();
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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

        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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

            if (\App\Privilege::isPermitted($moduleName, 'Save', $recordId)) {
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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_Record_Model' in method 'getRecordModelsFromRequest'.
Open

            $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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

Declaration of function getRecordModelsFromRequest(\App\Request $request) : \Vtiger_Record_Model should be compatible with function getRecordModelsFromRequest(\App\Request $request) : \Vtiger_Record_Model[] defined in /code/modules/Vtiger/actions/MassSave.php:53
Open

    public function getRecordModelsFromRequest(App\Request $request)
Severity: Minor
Found in modules/Users/actions/MassSave.php by phan

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

            $recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();
Severity: Critical
Found in modules/Users/actions/MassSave.php by phan

Argument 2 (module) is \Vtiger_Module_Model|\vtlib\Module|\vtlib\ModuleBasic but \Vtiger_Record_Model::getInstanceById() takes string defined at /code/modules/Vtiger/models/Record.php:763
Open

            $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);
Severity: Minor
Found in modules/Users/actions/MassSave.php by phan

Returning type array<int>|array{}</int> but getRecordModelsFromRequest() is declared to return \Vtiger_Record_Model
Open

        return $recordModels;
Severity: Minor
Found in modules/Users/actions/MassSave.php by phan

Class \Vtiger_Record_Model was passed to foreach, but it does not extend Traversable. This may be intentional, because some of that class's declared properties are accessible from this context. (This check excludes dynamic properties)
Open

        foreach ($recordModels as $recordId => $recordModel) {
Severity: Minor
Found in modules/Users/actions/MassSave.php by phan

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

class Users_MassSave_Action extends Vtiger_MassSave_Action

The class Users_MassSave_Action is not named in CamelCase.
Open

class Users_MassSave_Action extends Vtiger_MassSave_Action
{
    /** {@inheritdoc} */
    public function checkPermission(App\Request $request)
    {
Severity: Minor
Found in modules/Users/actions/MassSave.php by phpmd

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

    /** {@inheritdoc} */

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

     * @return Vtiger_Record_Model or Module specific Record Model instance

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

    {

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

                continue;

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 (!$currentUserModel->isAdminUser()) {

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

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

            $recordModels[$recordId] = $recordModel;

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

        $response->setResult(true);

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

        if (empty($recordIds) && 'all' === $request->getRaw('selected_ids')) {

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

        }

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

        $recordModels = [];

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

        $recordModels = $this->getRecordModelsFromRequest($request);

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

     * Function to get the record model based on the request parameters.

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

    public function getRecordModelsFromRequest(App\Request $request)

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

            if (!$recordModel->isEditable()) {

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

        }

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

                $recordModels[$recordId] = false;

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

                    $fieldModel->getUITypeModel()->setValueFromRequest($request, $recordModel);

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

        return $recordModels;

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

     *

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

        $recordIds = self::getRecordsListFromRequest($request);

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

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

        foreach ($recordModels as $recordId => $recordModel) {

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

                $recordModel->save();

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

        $fieldModelList = $moduleModel->getFields();

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

     */

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

        foreach ($recordIds as $recordId) {

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

            $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);

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

            foreach ($fieldModelList as $fieldName => $fieldModel) {

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

    public function checkPermission(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

            $recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();

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

                if ($fieldModel->isWritable() && $request->has($fieldName)) {

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

            }

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

        $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

            $recordModel->setId($recordId);

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

    {

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

        $moduleName = $request->getModule();

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

    }

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

        $currentUserModel = Users_Record_Model::getCurrentUserModel();

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

            if (\App\Privilege::isPermitted($moduleName, 'Save', $recordId)) {

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

        $moduleName = $request->getModule();

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

class Users_MassSave_Action extends Vtiger_MassSave_Action

There are no issues that match your filters.

Category
Status