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();
}
- Read upRead up
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'])
- Read upRead up
- Exclude checks
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'])
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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;
- Read upRead up
- Exclude checks
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
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$permissions = (new \App\Db\Query())->select(['name'])
- Exclude checks
Call to method getUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userModel = \App\User::getUserModel($userId);
- Exclude checks
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);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$modules = (new \App\Db\Query())->select(['name'])
- Exclude checks
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;
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userId = \App\User::getCurrentUserId();
- Exclude checks
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;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\in_array($moduleName, self::getActiveModules()) && (
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static function getPermittedModulesByUser(int $userId): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Cache::save($cacheName, '', $modules, \App\Cache::MEDIUM);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userId = \App\User::getCurrentUserId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static function getActiveModules(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const ACCESS_TABLE_NAME = 'a_#__settings_access';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets permitted modules by user ID.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['user' => $userId, 'status' => self::MODULE_STATUS_ACTIVE])->column();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Table name with settings modules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\in_array($moduleName, self::EXCEPTIONS)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
->innerJoin(self::ACCESS_TABLE_NAME, self::MODULES_TABLE_NAME . '.id=' . self::ACCESS_TABLE_NAME . '.module_id')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $modules) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $userId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Exceptions. Modules without authorization.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| \in_array($moduleName, self::getPermittedModulesByUser($userId))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = \App\Cache::has($cacheName, '') ? \App\Cache::get($cacheName, '') : null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cacheName = 'AdminActiveModules';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const MODULES_TABLE_NAME = 'a_#__settings_modules';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$permissions = \App\Cache::has($cacheName, $userId) ? \App\Cache::get($cacheName, $userId) : null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $permissions) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$permissions = (new \App\Db\Query())->select(['name'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $permissions;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from(self::MODULES_TABLE_NAME)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['status' => self::MODULE_STATUS_ACTIVE])->column();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const EXCEPTIONS = ['Vtiger', 'YetiForce'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userModel->isAdmin()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cacheName = 'AdminPermittedModulesByUser';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Module status active.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets active setting modules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = (new \App\Db\Query())->select(['name'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ($userModel->isAdmin() || $userModel->isSuperUser()) && (
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to check permission.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from(self::MODULES_TABLE_NAME)
- Exclude checks
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')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Table name with accesses.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function isPermitted(string $moduleName, int $userId = null): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userModel = \App\User::getUserModel($userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| ($userModel->isAdmin() && 'AdminAccess' === $moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Cache::save($cacheName, $userId, $permissions, \App\Cache::MEDIUM);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const MODULE_STATUS_ACTIVE = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| (
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks