Function setUpdater
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
{
$params = [
'module' => $moduleName,
'type' => $type,
- 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 setUpdater
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
{
$params = [
'module' => $moduleName,
'type' => $type,
Function update
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function update($record, $moduleName)
{
$searchUsers = $recordAccessUsers = '';
$users = Fields\Owner::getUsersIds();
$searchable = isset(\App\RecordSearch::getSearchableModules()[$moduleName]);
- 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
The method setUpdater() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
{
$params = [
'module' => $moduleName,
'type' => $type,
- 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 18 to the 15 allowed. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
- 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 setUpdater has a boolean flag argument $record, which is a certain sign of a Single Responsibility Principle violation. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
- 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
The method checkGlobalSearchPermissions has a boolean flag argument $userId, which is a certain sign of a Single Responsibility Principle violation. Open
public static function checkGlobalSearchPermissions($moduleName, $userId = false)
- 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
The method setUpdater has a boolean flag argument $priority, which is a certain sign of a Single Responsibility Principle violation. Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
- 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
Avoid using static access to class 'App\Privilege' in method 'update'. Open
if (Privilege::isPermitted($moduleName, 'DetailView', $record, $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\Fields\Owner' in method 'updateRecordAccess'. Open
$users = Fields\Owner::getUsersIds();
- 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 'checkGlobalSearchPermissions'. Open
$userId = 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 '\vtlib\Functions' in method 'setAllUpdater'. Open
$modules = \vtlib\Functions::getAllModules();
- 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 'updateOnRecordSave'. Open
if (!Config::security('CACHING_PERMISSION_TO_RECORD')) {
- 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 'setAllUpdater'. Open
if (Config::module('ModTracker', 'WATCHDOG')) {
- 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\RecordSearch' in method 'update'. Open
}
- 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 'updateSearch'. Open
if (static::checkGlobalSearchPermissions($moduleName, $userId) || Privilege::isPermitted($moduleName, 'DetailView', $record, $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\Privilege' in method 'updateRecordAccess'. Open
if (Privilege::isPermitted($moduleName, 'DetailView', $record, $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\Fields\Owner' in method 'update'. Open
$users = Fields\Owner::getUsersIds();
- 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\Fields\Owner' in method 'updateSearch'. Open
$users = Fields\Owner::getUsersIds();
- 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\Db' in method 'setUpdater'. Open
$db = Db::getInstance('admin');
- 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 'setAllUpdater'. Open
Cache::clear();
- 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 '\Vtiger_Watchdog_Model' in method 'setAllUpdater'. Open
\Vtiger_Watchdog_Model::reloadCache();
- 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
The method setUpdater uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
if (false === $row) {
$insert = true;
$params['type'] = 0;
- Read upRead up
- Exclude checks
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\PrivilegeAdvanced' in method 'setAllUpdater'. Open
PrivilegeAdvanced::reloadCache();
- 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 "s_#__privileges_updater" 5 times. Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 1])->limit(1)->one();
- 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" 4 times. Open
$dataReader = (new Db\Query())->select(['userid', 'searchunpriv'])->from('vtiger_user2role')
- 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 "crmid" 9 times. Open
$createCommand->update('vtiger_crmentity', ['users' => $recordAccessUsers], ['crmid' => $record])->execute();
- 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 "module" 5 times. Open
'module' => $moduleName,
- 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 "DetailView" 3 times. Open
if (Privilege::isPermitted($moduleName, 'DetailView', $record, $userId)) {
- 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.
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new Db\Query())->select(['userid', 'searchunpriv'])->from('vtiger_user2role')
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userId = User::getCurrentUserId();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- Exclude checks
Suspicious array access to false
Open
static::$globalSearchUsersCache[$row['userid']] = explode(',', $row['searchunpriv']);
- Exclude checks
Default value for int
$record
can't be false
Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
- Exclude checks
Assigning array{}
to property but \App\PrivilegeUpdater::$globalSearchUsersCache
is false
Open
static::$globalSearchUsersCache = [];
- Exclude checks
Call to method getUsersIds
from undeclared class \App\Fields\Owner
Open
$users = Fields\Owner::getUsersIds();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$createCommand = Db::getInstance()->createCommand();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
Db::getInstance()->createCommand()
- Exclude checks
Default value for int
$priority
can't be false
Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 1)
- Exclude checks
Call to method getUsersIds
from undeclared class \App\Fields\Owner
Open
$users = Fields\Owner::getUsersIds();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
Db::getInstance()->createCommand()
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 1])->limit(1)->one();
- Exclude checks
Returning type false
but getGlobalSearchUsers()
is declared to return array
Open
return static::$globalSearchUsersCache;
- Exclude checks
Call to method getUsersIds
from undeclared class \App\Fields\Owner
Open
$users = Fields\Owner::getUsersIds();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->update('s_#__privileges_updater', $params, ['module' => $moduleName, 'type' => $type])->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->insert('s_#__privileges_updater', $params)->execute();
- Exclude checks
Default value for int
$userId
can't be false
Open
public static function checkGlobalSearchPermissions($moduleName, $userId = false)
- Exclude checks
Assigning array<int>[]</int>
to property but \App\PrivilegeUpdater::$globalSearchUsersCache
is false
Open
static::$globalSearchUsersCache[$row['userid']] = explode(',', $row['searchunpriv']);
- Exclude checks
Avoid excessively long variable names like $globalSearchPermissionsCache. Keep variable name length under 20. Open
private static $globalSearchPermissionsCache = [];
- 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
Avoid excessively long variable names like $globalSearchUsersCache. Keep variable name length under 20. Open
private static $globalSearchUsersCache = false;
- 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
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = Db::getInstance('admin');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
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
$createCommand = Db::getInstance()->createCommand();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = true;
- 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 int $record
- 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
* Updating permissions to records.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (static::checkGlobalSearchPermissions($moduleName, $userId) || Privilege::isPermitted($moduleName, 'DetailView', $record, $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
->update('vtiger_crmentity', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $priority
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => $type,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$users = Fields\Owner::getUsersIds();
- 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
$searchUsers .= ',' . $userId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($users as $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
$recordAccessUsers .= ',';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'users' => $recordAccessUsers,
- 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
$params['priority'] = $priority;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Checking if user can search globally.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset(static::$globalSearchPermissionsCache[$userId][$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
private static $globalSearchUsersCache = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers = $recordAccessUsers = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
if (static::checkGlobalSearchPermissions($moduleName, $userId) || Privilege::isPermitted($moduleName, 'DetailView', $record, $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
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordAccessUsers = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($users[$userId]) && \in_array($moduleName, $users[$userId])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['<>', 'vtiger_role.searchunpriv', ''])
- 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
], 'crmid = ' . $record)
- 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 (!$userId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$globalSearchUsersCache = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function update($record, $moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$users = Fields\Owner::getUsersIds();
- 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
/**
- 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($recordAccessUsers)) {
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
$createCommand->update('u_#__crmentity_search_label', ['userid' => $searchUsers], ['crmid' => $record])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($searchUsers)) {
- 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
foreach ($users as &$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
Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $moduleName Module 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
$params['crmid'] = $record;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false === $record) {
- 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
* Loading a list of modules for users with permissions for global search.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getGlobalSearchUsers()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers .= ',' . $userId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($searchable) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Updating permissions to global search.
- 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
return static::$globalSearchPermissionsCache[$userId][$moduleName];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Updating permissions to records and global search.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($users as &$userId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Db::getInstance()->createCommand()
- 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
}
- 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
->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'module' => $moduleName,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query = new Db\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
$userId = 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
if (!static::$globalSearchUsersCache) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new Db\Query())->select(['userid', 'searchunpriv'])->from('vtiger_user2role')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$globalSearchUsersCache[$row['userid']] = explode(',', $row['searchunpriv']);
- 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
} elseif ($searchable && static::checkGlobalSearchPermissions($moduleName, $userId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordAccessUsers .= ',';
- 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($recordAccessUsers)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$update = true;
- 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::$globalSearchPermissionsCache[$userId][$moduleName] = $return;
- 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::$globalSearchUsersCache;
- 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 int $record
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Privilege::isPermitted($moduleName, 'DetailView', $record, $userId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($record) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$insert = $update = $row = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 != $row['crmid']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $globalSearchPermissionsCache = [];
- 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
$users = static::getGlobalSearchUsers();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordAccessUsers .= ',' . $userId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers .= ',';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($priority) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false === $row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::setUpdater($module['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function checkGlobalSearchPermissions($moduleName, $userId = false)
- 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 array
- 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 $record If type = 1 starting number if type = 0 record ID
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function setUpdater($moduleName, $record = false, $priority = false, $type = 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
} elseif (false === $record) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- 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
* @param int $record
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchable = isset(\App\RecordSearch::getSearchableModules()[$moduleName]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Privilege::isPermitted($moduleName, 'DetailView', $record, $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
$createCommand->update('vtiger_crmentity', ['users' => $recordAccessUsers], ['crmid' => $record])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers = $searchUsers ? $searchUsers . ',' : $searchUsers;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$createCommand->update('u_#__crmentity_search_label', ['userid' => $searchUsers], ['crmid' => $record])->execute();
- 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
$users = Fields\Owner::getUsersIds();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$searchUsers .= ',' . $userId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->update('u_#__crmentity_search_label', ['userid' => $searchUsers], ['crmid' => $record])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordAccessUsers .= ',' . $userId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Add to global permissions update queue.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = \vtlib\Functions::getAllModules();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$insert = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false === $row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Config::module('ModTracker', 'WATCHDOG')) {
- 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
$params['crmid'] = 0;
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- 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
$db->createCommand()->insert('s_#__privileges_updater', $params)->execute();
- 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 ($update) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Updating permissions to all modules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \Vtiger_Record_Model $record
- 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
foreach ($modules as $module) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function updateOnRecordSave(\Vtiger_Record_Model $record)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::setUpdater($record->getModuleName(), $record->getId(), 6, 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($record < $row['crmid']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- 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 ($insert) {
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['type'] = 0;
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$db->createCommand()->update('s_#__privileges_updater', $params, ['module' => $moduleName, 'type' => $type])->execute();
- 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
Cache::clear();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update permissions while saving record.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->leftJoin('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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function updateSearch($record, $moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function updateRecordAccess($record, $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
$params = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 1])->limit(1)->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->createCommand()->update('s_#__privileges_updater', $params, ['module' => $moduleName, 'type' => $type])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!Config::security('CACHING_PERMISSION_TO_RECORD')) {
- 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
$insert = true;
- 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
$insert = true;
- 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
\Vtiger_Watchdog_Model::reloadCache();
- 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
$db = Db::getInstance('admin');
- 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
public static function setAllUpdater()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
PrivilegeAdvanced::reloadCache();
- 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
$row = $query->from('s_#__privileges_updater')->where(['module' => $moduleName, 'type' => 0, 'crmid' => $record])->limit(1)->one();
- 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