YetiForceCompany/YetiForceCRM

View on GitHub
app/Security/AdminAccess.php

Summary

Maintainability
A
35 mins
Test Coverage
D
66%

Function isPermitted has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function isPermitted(string $moduleName, int $userId = null): bool
    {
        if (null === $userId) {
            $userId = \App\User::getCurrentUserId();
        }
Severity: Minor
Found in app/Security/AdminAccess.php - About 35 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 '74', column '24').
Open

            $permissions = (new \App\Db\Query())->select(['name'])
Severity: Minor
Found in app/Security/AdminAccess.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 '93', column '20').
Open

            $modules = (new \App\Db\Query())->select(['name'])
Severity: Minor
Found in app/Security/AdminAccess.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\User' in method 'isPermitted'.
Open

            $userId = \App\User::getCurrentUserId();
Severity: Minor
Found in app/Security/AdminAccess.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 'getPermittedModulesByUser'.
Open

        $permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
Severity: Minor
Found in app/Security/AdminAccess.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\User' in method 'isPermitted'.
Open

        $userModel = \App\User::getUserModel($userId);
Severity: Minor
Found in app/Security/AdminAccess.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 'getPermittedModulesByUser'.
Open

        $permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
Severity: Minor
Found in app/Security/AdminAccess.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 'getPermittedModulesByUser'.
Open

            \App\Cache::save($cacheName, $userId, $permissions, \App\Cache::MEDIUM);
Severity: Minor
Found in app/Security/AdminAccess.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 'getActiveModules'.
Open

            \App\Cache::save($cacheName, '', $modules, \App\Cache::MEDIUM);
Severity: Minor
Found in app/Security/AdminAccess.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 'getActiveModules'.
Open

        $modules = \App\Cache::has($cacheName, '') ? \App\Cache::get($cacheName, '') : null;
Severity: Minor
Found in app/Security/AdminAccess.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 'getActiveModules'.
Open

        $modules = \App\Cache::has($cacheName, '') ? \App\Cache::get($cacheName, '') : null;
Severity: Minor
Found in app/Security/AdminAccess.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

Doc-block of $userId in isPermitted is phpdoc param type int which is not a permitted replacement of the nullable param type ?int declared in the signature ('?T' should be documented as 'T|null' or '?T')
Open

     * @param int    $userId
Severity: Minor
Found in app/Security/AdminAccess.php by phan

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

            $permissions = (new \App\Db\Query())->select(['name'])
Severity: Critical
Found in app/Security/AdminAccess.php by phan

Call to method getUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

        $userModel = \App\User::getUserModel($userId);
Severity: Critical
Found in app/Security/AdminAccess.php by phan

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

            \App\Cache::save($cacheName, $userId, $permissions, \App\Cache::MEDIUM);
Severity: Minor
Found in app/Security/AdminAccess.php by phan

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

            $modules = (new \App\Db\Query())->select(['name'])
Severity: Critical
Found in app/Security/AdminAccess.php by phan

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

        $permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
Severity: Minor
Found in app/Security/AdminAccess.php by phan

Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            $userId = \App\User::getCurrentUserId();
Severity: Critical
Found in app/Security/AdminAccess.php by phan

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

        $permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
Severity: Minor
Found in app/Security/AdminAccess.php by phan

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

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

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

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

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

                    \in_array($moduleName, self::getActiveModules()) && (
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

            );
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    private static function getPermittedModulesByUser(int $userId): array
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

            \App\Cache::save($cacheName, '', $modules, \App\Cache::MEDIUM);
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

            $userId = \App\User::getCurrentUserId();
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    private static function getActiveModules(): array
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

    public const ACCESS_TABLE_NAME = 'a_#__settings_access';
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * Gets permitted modules by user ID.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                ->where(['user' => $userId, 'status' => self::MODULE_STATUS_ACTIVE])->column();
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

     * Table name with settings modules.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

     * @param string $moduleName
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * @param int    $userId
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

                \in_array($moduleName, self::EXCEPTIONS)
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * @param int $userId
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * @return string[]
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

Line exceeds 120 characters; contains 128 characters
Open

                ->innerJoin(self::ACCESS_TABLE_NAME, self::MODULES_TABLE_NAME . '.id=' . self::ACCESS_TABLE_NAME . '.module_id')
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        if (null === $modules) {
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        if (null === $userId) {
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

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

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

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

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

     * Exceptions. Modules without authorization.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                        || \in_array($moduleName, self::getPermittedModulesByUser($userId))
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        $modules = \App\Cache::has($cacheName, '') ? \App\Cache::get($cacheName, '') : null;
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        $cacheName = 'AdminActiveModules';
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    public const MODULES_TABLE_NAME = 'a_#__settings_modules';
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

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

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

                    )
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        $permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        if (null === $permissions) {
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

            $permissions = (new \App\Db\Query())->select(['name'])
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        return $permissions;
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

                ->from(self::MODULES_TABLE_NAME)
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                ->where(['status' => self::MODULE_STATUS_ACTIVE])->column();
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    public const EXCEPTIONS = ['Vtiger', 'YetiForce'];
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                        $userModel->isAdmin()
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

        $cacheName = 'AdminPermittedModulesByUser';
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * Module status active.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

     * Gets active setting modules.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

            $modules = (new \App\Db\Query())->select(['name'])
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

        return ($userModel->isAdmin() || $userModel->isSuperUser()) && (
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

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

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

                )
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * Function to check permission.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

     * @return bool
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

                ->from(self::MODULES_TABLE_NAME)
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                ->innerJoin(self::ACCESS_TABLE_NAME, self::MODULES_TABLE_NAME . '.id=' . self::ACCESS_TABLE_NAME . '.module_id')
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * Table name with accesses.
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    public static function isPermitted(string $moduleName, int $userId = null): bool
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        $userModel = \App\User::getUserModel($userId);
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                || ($userModel->isAdmin() && 'AdminAccess' === $moduleName)
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

            \App\Cache::save($cacheName, $userId, $permissions, \App\Cache::MEDIUM);
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

     * @return string[]
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

        return $modules;
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

    public const MODULE_STATUS_ACTIVE = 1;
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

                || (
Severity: Minor
Found in app/Security/AdminAccess.php by phpcodesniffer

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

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

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

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

There are no issues that match your filters.

Category
Status