Function getPrivilegeQuery
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
- 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
Method getPrivilegeQuery
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
The method getPrivilegeQuery() has an NPath complexity of 77088. The configured NPath complexity threshold is 200. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method getPrivilegeQuery() has a Cyclomatic Complexity of 29. The configured cyclomatic complexity threshold is 10. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 45 to the 15 allowed. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The method getConditions has a boolean flag argument $user, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getConditions(Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '127', column '24'). Open
$subQuery = (new \App\Db\Query())->select(['shareduserid'])
- 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 '114', column '22'). Open
$subQuery = (new \App\Db\Query())->select(['userid'])
- 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 '133', column '24'). Open
$subQuery = (new \App\Db\Query())->select(['sharedgroupid'])
- 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 '78', column '22'). Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- 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
The method getPrivilegeQuery has a boolean flag argument $user, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '141', column '22'). Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- 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 '\Users_Privileges_Model' in method 'getPrivilegeQuery'. Open
$userModel = \Users_Privileges_Model::getInstanceById($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\Config' in method 'getPrivilegeQuery'. Open
if (\App\Config::security('PERMITTED_BY_ROLES')) {
- 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\Config' in method 'getPrivilegeQuery'. Open
if (!$userModel->isAdminUser() && \App\Config::security('PERMITTED_BY_PRIVATE_FIELD') && ($fieldInfo = \App\Field::getFieldInfo('private', $moduleName)) && \in_array($fieldInfo['presence'], [0, 2])) {
- 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\Config' in method 'getPrivilegeQuery'. Open
if (\App\Config::security('PERMITTED_BY_SHARED_OWNERS')) {
- 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\Config' in method 'getPrivilegeQuery'. Open
if (\App\Config::security('PERMITTED_BY_SHARING')) {
- 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 assigning values to variables in if clauses and the like (line '72', column '93'). Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\User' in method 'getPrivilegeQuery'. Open
$sharingPrivileges = \App\User::getSharingFile($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\Field' in method 'getPrivilegeQuery'. Open
if (!$userModel->isAdminUser() && \App\Config::security('PERMITTED_BY_PRIVATE_FIELD') && ($fieldInfo = \App\Field::getFieldInfo('private', $moduleName)) && \in_array($fieldInfo['presence'], [0, 2])) {
- 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 '\vtlib\Functions' in method 'getPrivilegeQuery'. Open
$recordMetaData = \vtlib\Functions::getCRMRecordMetadata($relatedRecord);
- 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\Config' in method 'getPrivilegeQuery'. Open
if (($modules = \App\Config::security('permittedModulesByCreatorField')) && \in_array($moduleName, $modules)) {
- 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\Module' in method 'getPrivilegeQuery'. Open
$tabId = Module::getModuleId($moduleName);
- 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 '\Users_Privileges_Model' in method 'getPrivilegeQuery'. Open
$parentRecord = \Users_Privileges_Model::getParentRecord($relatedRecord, false, $role->get('listrelatedrecord'));
- 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\Config' in method 'getPrivilegeQuery'. Open
if (\App\Config::security('PERMITTED_BY_SHARED_OWNERS')) {
- 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\Config' in method 'getPrivilegeQuery'. Open
if (\App\Config::security('PERMITTED_BY_RECORD_HIERARCHY') && !empty($relatedRecord)) {
- 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 assigning values to variables in if clauses and the like (line '109', column '9'). Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
{
if ($user && $user instanceof User) {
$userId = $user->getId();
} elseif (!$user) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\User' in method 'getPrivilegeQuery'. 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\Privilege' in method 'getPrivilegeQuery'. Open
$recordPermission = Privilege::isPermitted($recordMetaData['setype'], 'DetailView', $relatedRecord, $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
Define a constant instead of duplicating this literal "listrelatedrecord" 3 times. Open
if (2 == $role->get('listrelatedrecord')) {
- Read upRead up
- Exclude checks
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 "vtiger_crmentity.smownerid" 6 times. Open
$subConditions = ['or', ['vtiger_crmentity.smownerid' => $owners]];
- Read upRead up
- Exclude checks
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 "userid" 5 times. Open
->where(['userid' => $owners]);
- Read upRead up
- Exclude checks
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 1 (userId)
is null
but \Users_Privileges_Model::getInstanceById()
takes int
defined at /code/modules/Users/models/Privileges.php:159
Open
$userModel = \Users_Privileges_Model::getInstanceById($userId);
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere($conditions);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new \App\Db\Query())->select(['userid'])
- Exclude checks
Call to method getId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userId = $user->getId();
- Exclude checks
Returning type ''
but getPrivilegeQuery()
is declared to return void
Open
return '';
- Exclude checks
Checking instanceof against undeclared class \App\User
(Did you mean class \Tests\App\User) Open
if ($user && $user instanceof User) {
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- Exclude checks
Parameter $user
has undeclared type \App\User
(Did you mean class \Tests\App\User) Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Default value for int
$user
can't be false
Open
public static function getConditions(Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->groups
Open
if (!empty($userModel->groups)) {
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->profile_global_permission
Open
if (!$userModel->isAdminUser() && 1 == $userModel->profile_global_permission[1] && 1 == $userModel->profile_global_permission[2] && 3 === ($userModel->defaultOrgSharingPermission[$tabId] ?? null)) {
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->parent_role_seq
Open
$parentRoleSeq = $userModel->parent_role_seq;
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->groups
Open
$owners = array_merge([$userId], $userModel->groups);
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->defaultOrgSharingPermission
Open
if (!$userModel->isAdminUser() && 1 == $userModel->profile_global_permission[1] && 1 == $userModel->profile_global_permission[2] && 3 === ($userModel->defaultOrgSharingPermission[$tabId] ?? 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
Reference to undeclared property \Users_Privileges_Model->groups
Open
$conditions[] = ['vtiger_crmentity.smownerid' => $userModel->groups];
- Exclude checks
Default value for \App\User|int
$user
can't be false
Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new \App\Db\Query())->select(['sharedgroupid'])
- Exclude checks
Reference to undeclared property \Users_Privileges_Model->groups
Open
->where(['userid' => array_merge([$userId], $userModel->groups)]);
- Exclude checks
Call to method getSharingFile
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$sharingPrivileges = \App\User::getSharingFile($userId);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new \App\Db\Query())->select(['shareduserid'])
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere($conditions);
- Exclude checks
Avoid excessively long variable names like $sharingPrivilegesModule. Keep variable name length under 20. Open
$sharingPrivilegesModule = $sharingPrivileges['permission'][$moduleName];
- Read upRead up
- Exclude checks
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
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $relatedRecord
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subConditions = ['or', ['vtiger_crmentity.smownerid' => $owners]];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$role = $userModel->getRoleDetail();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedRecord = $parentRecord;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordMetaData = \vtlib\Functions::getCRMRecordMetadata($relatedRecord);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordPermission = Privilege::isPermitted($recordMetaData['setype'], 'DetailView', $relatedRecord, $userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($modules = \App\Config::security('permittedModulesByCreatorField')) && \in_array($moduleName, $modules)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Config::security('PERMITTED_BY_SHARING')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.crmid' => $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $relatedRecord
- 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
if (!empty($userModel->groups)) {
- 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
$sharingPrivileges = \App\User::getSharingFile($userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($sharingRuleInfo['ROLE'])) {
- 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
$query->andWhere($conditions);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getPrivilegeQuery(Db\Query $query, $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$owners = array_merge([$userId], $userModel->groups);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['and', ['vtiger_crmentity.private' => 1], $subConditions];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.smownerid' => $userId];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['like', 'vtiger_role.parentrole', "$parentRoleSeq::%", false]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('u_yf_crmentity_showners')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Interpreter for privilege.
- 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 setPermissionInterpreter(string $className)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Db\Query $query
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$userModel->isAdminUser() && \App\Config::security('PERMITTED_BY_PRIVATE_FIELD') && ($fieldInfo = \App\Field::getFieldInfo('private', $moduleName)) && \in_array($fieldInfo['presence'], [0, 2])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.private' => 0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tabId = Module::getModuleId($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['userid' => $userId, 'tabid' => $tabId]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($conditions)) {
- 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
if (2 == $role->get('listrelatedrecord')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_users', 'vtiger_user2role.userid = vtiger_users.id')
- 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
$subQuery = (new \App\Db\Query())->select(['shareduserid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($sharingRuleInfo['GROUP'])) {
- 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
$conditions = ['or'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($parentRecord) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 != $role->get('listrelatedrecord')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_tmp_read_group_sharing_per')
- 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 $interpreter;
- 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
if (!empty(static::$interpreter) && class_exists(static::$interpreter)) {
- 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
$conditions[] = ['vtiger_crmentity.smownerid' => $userModel->groups];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_role', 'vtiger_user2role.roleid = vtiger_role.roleid')
- 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 $className
- 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
/**
- 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
} elseif (!$user) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Config::security('PERMITTED_BY_SHARED_OWNERS')) {
- Exclude checks
Line exceeds 120 characters; contains 208 characters Open
if (!$userModel->isAdminUser() && \App\Config::security('PERMITTED_BY_PRIVATE_FIELD') && ($fieldInfo = \App\Field::getFieldInfo('private', $moduleName)) && \in_array($fieldInfo['presence'], [0, 2])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
$parentRecord = \Users_Privileges_Model::getParentRecord($relatedRecord, false, $role->get('listrelatedrecord'));
- 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
if ($recordPermission) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($sharingPrivileges['permission'][$moduleName])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new \App\Db\Query())->select(['sharedgroupid'])
- 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
if (!$userModel->isAdminUser() && 1 == $userModel->profile_global_permission[1] && 1 == $userModel->profile_global_permission[2] && 3 === ($userModel->defaultOrgSharingPermission[$tabId] ?? null)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new \App\Db\Query())->select(['userid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$interpreter = $className;
- 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 (static::$interpreter)::getConditions($query, $moduleName, $user, $relatedRecord);
- 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('u_yf_crmentity_showners')
- 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
$conditions = ['or'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.smownerid' => $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Sets interpreter.
- 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
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int|\App\User $user
- 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
$subConditions[] = ['vtiger_crmentity.crmid' => $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRecord = \Users_Privileges_Model::getParentRecord($relatedRecord, false, $role->get('listrelatedrecord'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['userid' => $userId, 'tabid' => $tabId]);
- 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
* Undocumented function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $user
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getConditions(Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($user && $user instanceof User) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userModel = \Users_Privileges_Model::getInstanceById($userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = (new \App\Db\Query())->select(['crmid'])->distinct()
- Exclude checks
Line exceeds 120 characters; contains 206 characters Open
if (!$userModel->isAdminUser() && 1 == $userModel->profile_global_permission[1] && 1 == $userModel->profile_global_permission[2] && 3 === ($userModel->defaultOrgSharingPermission[$tabId] ?? null)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.smcreatorid' => $userId];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_user2role')
- 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
if (\App\Config::security('PERMITTED_BY_SHARED_OWNERS')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['userid' => array_merge([$userId], $userModel->groups)]);
- 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 void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- 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
* Undocumented function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userId = $user->getId();
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
if (($modules = \App\Config::security('permittedModulesByCreatorField')) && \in_array($moduleName, $modules)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sharingRuleInfo = $sharingPrivilegesModule['read'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['userid' => $owners]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->andWhere($conditions);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_tmp_read_user_sharing_per')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.smownerid' => $subQuery];
- 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 \App\Db\Query $query
- 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
if (\App\Config::security('PERMITTED_BY_ROLES')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sharingPrivilegesModule = $sharingPrivileges['permission'][$moduleName];
- 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
if (\App\Config::security('PERMITTED_BY_RECORD_HIERARCHY') && !empty($relatedRecord)) {
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
$recordPermission = Privilege::isPermitted($recordMetaData['setype'], 'DetailView', $relatedRecord, $userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentRoleSeq = $userModel->parent_role_seq;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions[] = ['vtiger_crmentity.smownerid' => $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks