YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

Function setFilterPermissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function setFilterPermissions(App\Request $request)
    {
        $user = $request->getByType('user', 'Text');
        $add = $request->getBoolean('operator');

Severity: Minor
Found in modules/Settings/CustomView/actions/SaveAjax.php - About 25 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 '106', 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 '69', 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 '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 '99', column '15').
Open

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

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 '53', 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 '\App\Language' in method 'upadteSequences'.
Open

            'message' => \App\Language::translate('LBL_SAVE_SEQUENCES', $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 'setFilterPermissions'.
Open

            $data['message'] = \App\Language::translate('LBL_SAVE_CONFIG', $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 'updateField'.
Open

            'message' => \App\Language::translate('Saving CustomView', $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 'CustomView_Record_Model' in method 'setFilterPermissions'.
Open

        $recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

            'message' => \App\Language::translate('Delete CustomView', $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_CustomView_Module_Model' in method 'upadteSequences'.
Open

        Settings_CustomView_Module_Model::upadteSequences($params);

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 'CustomView_Record_Model' in method 'updateField'.
Open

        $recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

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

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.

Remove the code after this "throw".
Open

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

Jump statements (return, break, continue, and goto) and throw expressions move control flow out of the current code block. Typically, any statements in a block that come after a jump or throw are simply wasted keystrokes lying in wait to confuse the unwary.

Rarely, as illustrated below, code after a jump or throw is reachable. However, such code is difficult to understand, and should be refactored.

Noncompliant Code Example

function fun($a) {
  $i = 10;
  return $i + $a;
  $i++;             // this is never executed
}

function foo($a) {
  if ($a == 5) {
    goto error;
  } else {
    // do the job
  }
  return;

  error:
    printf("don't use 5"); // this is reachable but unreadable

}

Compliant Solution

function fun($a) {
  $i = 10;
  return $i + $a;
}

function foo($a) {
  if ($a == 5) {
    handleError();
  } else {
    // do the job
  }
  return;
}

See

  • MISRA C:2004, 14.1 - There shall be no unreachable code
  • MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
  • MISRA C++:2008, 0-1-9 - There shall be no dead code
  • MISRA C:2012, 2.1 - A project shall not contain unreachable code
  • MISRA C:2012, 2.2 - There shall be no dead code
  • MITRE, CWE-561 - Dead Code
  • CERT, MSC56-J. - Detect and remove superfluous code and values
  • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
  • CERT, MSC07-CPP. - Detect and remove dead code

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

class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action

The class Settings_CustomView_SaveAjax_Action is not named in CamelCase.
Open

class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action
{
    /**
     * Constructor.
     */

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

        parent::__construct();

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

        $this->exposeMethod('setFilterPermissions');

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 = $add ? $recordModel->setDefaultForMember($user) : $recordModel->removeDefaultForMember($user);

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->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

        $response = new Vtiger_Response();

Line exceeds 120 characters; contains 122 characters
Open

                $result = $add ? $recordModel->setFeaturedForMember($user) : $recordModel->removeFeaturedForMember($user);

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

     * Constructor.

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

     * Action to delete filter.

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

    }

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

     * Action to update sequences.

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

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

        $this->exposeMethod('delete');

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

        $this->exposeMethod('updateField');

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

        $params = $request->getArray('param', 'Integer');

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

                $result = $add ? $recordModel->setFeaturedForMember($user) : $recordModel->removeFeaturedForMember($user);

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

                break;

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 = new Vtiger_Response();

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

     * @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

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

            'message' => \App\Language::translate('Delete CustomView', $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

    public function updateField(App\Request $request)

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

     * @param \App\Request $request

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

     * Action to set permissions.

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

        $add = $request->getBoolean('operator');

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

                break;

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

            $data['message'] = \App\Language::translate('LBL_SAVE_CONFIG', $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_CustomView_Module_Model::upadteSequences($params);

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

            case 'featured':

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

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

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

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

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

            default:

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

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

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

        switch ($request->getByType('type')) {

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

                break;

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

     * @param \App\Request $request

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

    public function delete(App\Request $request)

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

        $recordModel->set('mode', 'edit');

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

        $recordModel->setValueFromRequest($request, $request->getByType('name', \App\Purifier::STANDARD), 'value');

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

        $response->setResult($data);

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 = 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

        ]);

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

        $user = $request->getByType('user', 'Text');

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

        $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

     *

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

                break;

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

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

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->exposeMethod('upadteSequences');

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

        $recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

     */

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

    public function upadteSequences(App\Request $request)

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

                $result = $add ? $recordModel->setPrivilegesForMember($user) : $recordModel->removePrivilegesForMember($user);

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

        CustomView_Record_Model::getInstanceById($request->getInteger('cvid'))->delete();

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->setResult([

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

            case 'default':

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([

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

     * Action to update parameter in the filter.

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

        $recordModel = CustomView_Record_Model::getInstanceById($request->getInteger('cvid'));

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

            case 'permissions':

Line exceeds 120 characters; contains 126 characters
Open

                $result = $add ? $recordModel->setPrivilegesForMember($user) : $recordModel->removePrivilegesForMember($user);

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

class Settings_CustomView_SaveAjax_Action extends Settings_Vtiger_Basic_Action

There are no issues that match your filters.

Category
Status