YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/GlobalPermission/models/Record.php

Summary

Maintainability
A
0 mins
Test Coverage
F
48%

Missing class import via use statement (line '24', column '22').
Open

        $dataReader = (new App\Db\Query())->from('vtiger_profile2globalpermissions')

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\UserPrivilegesFile' in method 'recalculate'.
Open

                \App\UserPrivilegesFile::createUserPrivilegesfile($userId);

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

            \App\Privilege::setAllUpdater();

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

        $db = App\Db::getInstance();

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\Config' in method 'recalculate'.
Open

        $php_max_execution_time = \App\Config::main('php_max_execution_time');

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_Profiles_Record_Model' in method 'recalculate'.
Open

        $userIdsList = Settings_Profiles_Record_Model::getUsersList();

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

        $dataReader = (new App\Db\Query())->from('vtiger_profile2globalpermissions')

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

            $profileid = $row['profileid'];

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

            $actionId = $row['globalactionid'];

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.

Call to undeclared method \App\Db::createCommand
Open

        $db->createCommand()->delete('vtiger_profile2globalpermissions', ['profileid' => $profileID, 'globalactionid' => $globalactionid])->execute();

Method \Settings_GlobalPermission_Record_Model::getId is declared to return int but has no return value
Open

    public function getId()

Call to undeclared method \App\Db::createCommand
Open

        $db->createCommand()->insert('vtiger_profile2globalpermissions', [

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

        $dataReader = (new App\Db\Query())->from('vtiger_profile2globalpermissions')

Method \Settings_GlobalPermission_Record_Model::getName is declared to return string but has no return value
Open

    public function getName()

Avoid excessively long variable names like $php_max_execution_time. Keep variable name length under 20.
Open

        $php_max_execution_time = \App\Config::main('php_max_execution_time');

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

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

class Settings_GlobalPermission_Record_Model extends Settings_Vtiger_Record_Model

Avoid variables with short names like $db. Configured minimum length is 3.
Open

        $db = App\Db::getInstance();

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

The class Settings_GlobalPermission_Record_Model is not named in CamelCase.
Open

class Settings_GlobalPermission_Record_Model extends Settings_Vtiger_Record_Model
{
    const GLOBAL_ACTION_VIEW = 1;
    const GLOBAL_ACTION_EDIT = 2;

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

            $profileid = $row['profileid'];

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

            \App\Privilege::setAllUpdater();

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

    {

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

            $globalPermissions[$profileid]['description'] = $description;

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

    public static function recalculate()

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 $globalPermissions;

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

            $permissionId = $row['globalactionpermission'];

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

        }

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

        $dataReader->close();

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

        $db->createCommand()->delete('vtiger_profile2globalpermissions', ['profileid' => $profileID, 'globalactionid' => $globalactionid])->execute();

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

            'globalactionpermission' => $checked,

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

    }

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

        $php_max_execution_time = \App\Config::main('php_max_execution_time');

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

        if ($userIdsList) {

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

                \App\UserPrivilegesFile::createUserPrivilegesfile($userId);

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

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

        while ($row = $dataReader->read()) {

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

            $globalPermissions[$profileid]['profilename'] = $profilename;

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

        ])->execute();

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

    public static function getGlobalPermissions()

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

            $description = $row['description'];

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

    const GLOBAL_ACTION_VIEW = 1;

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

    public static function save($profileID, $globalactionid, $checked)

Line exceeds 120 characters; contains 150 characters
Open

        $db->createCommand()->delete('vtiger_profile2globalpermissions', ['profileid' => $profileID, 'globalactionid' => $globalactionid])->execute();

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

            'globalactionid' => $globalactionid,

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

        set_time_limit($php_max_execution_time);

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

    }

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

        $globalPermissions = [];

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

            $globalPermissions[$profileid]['gp_' . $actionId] = $permissionId;

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

        $db->createCommand()->insert('vtiger_profile2globalpermissions', [

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

        self::recalculate();

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

            foreach ($userIdsList as $userId) {

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

            ->leftJoin('vtiger_profile', 'vtiger_profile.profileid = vtiger_profile2globalpermissions.profileid')

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

    }

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

            $actionId = $row['globalactionid'];

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

            $profilename = $row['profilename'];

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 (1 == $globalactionid) {

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

    public function getName()

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

    {

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

            ->createCommand()->query();

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

            'profileid' => $profileID,

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

        $userIdsList = Settings_Profiles_Record_Model::getUsersList();

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

    const GLOBAL_ACTION_EDIT = 2;

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

        $dataReader = (new App\Db\Query())->from('vtiger_profile2globalpermissions')

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

    {

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

        $db = App\Db::getInstance();

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

    }

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

class Settings_GlobalPermission_Record_Model extends Settings_Vtiger_Record_Model

The variable $php_max_execution_time is not named in camelCase.
Open

    public static function recalculate()
    {
        $php_max_execution_time = \App\Config::main('php_max_execution_time');
        set_time_limit($php_max_execution_time);
        $userIdsList = Settings_Profiles_Record_Model::getUsersList();

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $php_max_execution_time is not named in camelCase.
Open

    public static function recalculate()
    {
        $php_max_execution_time = \App\Config::main('php_max_execution_time');
        set_time_limit($php_max_execution_time);
        $userIdsList = Settings_Profiles_Record_Model::getUsersList();

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

There are no issues that match your filters.

Category
Status