YetiForceCompany/YetiForceCRM

View on GitHub
app/MultiCompany.php

Summary

Maintainability
A
0 mins
Test Coverage
F
59%

Missing class import via use statement (line '68', column '27').
Open

            $rolesByCompany = (new \App\Db\Query())->select(['company', 'roleid'])->from('vtiger_role')->createCommand()->queryAllByGroup(2);
Severity: Minor
Found in app/MultiCompany.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 'App\Cache' in method 'getAll'.
Open

        if (Cache::has('getUsersByCompany', '')) {
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getUsersByCompany'.
Open

        if (Cache::has('getUsersByCompany', $companyId)) {
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getUsersByCompany'.
Open

        Cache::save('getUsersByCompany', $companyId, $rows);
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getAll'.
Open

            return Cache::get('getUsersByCompany', '');
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getUsersByCompany'.
Open

            return Cache::get('getUsersByCompany', $companyId);
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getAll'.
Open

        Cache::save('getUsersByCompany', '', $rows);
Severity: Minor
Found in app/MultiCompany.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

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

        } else {
            $rolesByCompany = (new \App\Db\Query())->select(['company', 'roleid'])->from('vtiger_role')->createCommand()->queryAllByGroup(2);
            Cache::save('getCompanyRoles', '', $rolesByCompany);
        }
Severity: Minor
Found in app/MultiCompany.php by phpmd

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 'App\Cache' in method 'getRolesByCompany'.
Open

        if (Cache::has('getCompanyRoles', '')) {
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getRolesByCompany'.
Open

            Cache::save('getCompanyRoles', '', $rolesByCompany);
Severity: Minor
Found in app/MultiCompany.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\Cache' in method 'getRolesByCompany'.
Open

            $rolesByCompany = Cache::get('getCompanyRoles', '');
Severity: Minor
Found in app/MultiCompany.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

Define a constant instead of duplicating this literal "getCompanyRoles" 3 times.
Open

        if (Cache::has('getCompanyRoles', '')) {
Severity: Critical
Found in app/MultiCompany.php by sonar-php

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 "getUsersByCompany" 6 times.
Open

        if (Cache::has('getUsersByCompany', $companyId)) {
Severity: Critical
Found in app/MultiCompany.php by sonar-php

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.

Argument 2 (key) is int but \App\Cache::get() takes string defined at /code/app/Cache.php:61
Open

            return Cache::get('getUsersByCompany', $companyId);
Severity: Minor
Found in app/MultiCompany.php by phan

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

            $rolesByCompany = (new \App\Db\Query())->select(['company', 'roleid'])->from('vtiger_role')->createCommand()->queryAllByGroup(2);
Severity: Critical
Found in app/MultiCompany.php by phan

Argument 2 (key) is int but \App\Cache::has() takes string defined at /code/app/Cache.php:74
Open

        if (Cache::has('getUsersByCompany', $companyId)) {
Severity: Minor
Found in app/MultiCompany.php by phan

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

        $rows = (new Db\Query())->select(['vtiger_user2role.userid'])->from('vtiger_user2role')
Severity: Critical
Found in app/MultiCompany.php by phan

Argument 2 (key) is int but \App\Cache::save() takes string defined at /code/app/Cache.php:89
Open

        Cache::save('getUsersByCompany', $companyId, $rows);
Severity: Minor
Found in app/MultiCompany.php by phan

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

        $rows = (new Db\Query())->select(['u_#__multicompany.*'])->from('u_#__multicompany')
Severity: Critical
Found in app/MultiCompany.php by phan

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

        return $rows;
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            return Cache::get('getUsersByCompany', '');
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * @param int $companyId
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * Get user ids by multi company id.
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            ->where(['vtiger_crmentity.deleted' => 0])->all() ?: [];
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        if (Cache::has('getUsersByCompany', $companyId)) {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        $rows = (new Db\Query())->select(['vtiger_user2role.userid'])->from('vtiger_user2role')
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            ->innerJoin('vtiger_crmentity', 'vtiger_crmentity.crmid = u_#__multicompany.multicompanyid')
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * Gets roles by company ID.
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            ->where(['vtiger_role.company' => $companyId])->column();
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    public static function getAll(): array
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        Cache::save('getUsersByCompany', '', $rows);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        if (Cache::has('getCompanyRoles', '')) {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            $rolesByCompany = (new \App\Db\Query())->select(['company', 'roleid'])->from('vtiger_role')->createCommand()->queryAllByGroup(2);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * @return array
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        if (Cache::has('getUsersByCompany', '')) {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        $rows = (new Db\Query())->select(['u_#__multicompany.*'])->from('u_#__multicompany')
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    public static function getUsersByCompany(int $companyId): array
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        Cache::save('getUsersByCompany', $companyId, $rows);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * @return array
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        return $rolesByCompany[$companyId] ?? [];
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * @param int $companyId
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            $rolesByCompany = Cache::get('getCompanyRoles', '');
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            Cache::save('getCompanyRoles', '', $rolesByCompany);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    public static function getRolesByCompany(int $companyId): array
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        } else {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            ->innerJoin('vtiger_role', 'vtiger_user2role.roleid = vtiger_role.roleid')
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        return $rows;
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

            return Cache::get('getUsersByCompany', $companyId);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * Get all multi company records.
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

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

     * @return int[]
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

Line exceeds 120 characters; contains 141 characters
Open

            $rolesByCompany = (new \App\Db\Query())->select(['company', 'roleid'])->from('vtiger_role')->createCommand()->queryAllByGroup(2);
Severity: Minor
Found in app/MultiCompany.php by phpcodesniffer

There are no issues that match your filters.

Category
Status