Function getByModule
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
{
if (Cache::has('App\Relation::getByModule', $moduleName)) {
$allRelations = Cache::get('App\Relation::getByModule', $moduleName);
} else {
- 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 getByModule
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
{
if (Cache::has('App\Relation::getByModule', $moduleName)) {
$allRelations = Cache::get('App\Relation::getByModule', $moduleName);
} else {
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed. Open
public static function getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
- 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 clearCacheByModule has a boolean flag argument $child, which is a certain sign of a Single Responsibility Principle violation. Open
public static function clearCacheByModule(string $moduleName, bool $child = true): void
- 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 clearCacheById has a boolean flag argument $parent, which is a certain sign of a Single Responsibility Principle violation. Open
public static function clearCacheById(int $relationId, bool $parent = true): void
- 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 getByModule has a boolean flag argument $onlyActive, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
- 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\Cache' in method 'getByModule'. Open
$allRelations = Cache::get('App\Relation::getByModule', $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 'App\Cache' in method 'getByModule'. Open
Cache::save('App\Relation::getByModule', $moduleName, $allRelations, Cache::LONG);
- 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 '150', column '19'). Open
public static function clearCacheById(int $relationId, bool $parent = true): void
{
if ($parent && ($relation = self::getById($relationId)) && ($moduleName = \App\Module::getModuleName($relation['tabid']))) {
self::clearCacheByModule($moduleName, false);
}
- 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\Cache' in method 'getById'. Open
if (Cache::has('App\Relation::getById', $relationId)) {
- 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 'getById'. Open
return Cache::get('App\Relation::getById', $relationId);
- 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 'getById'. Open
Cache::save('App\Relation::getById', $relationId, $row, Cache::LONG);
- 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 'clearCacheById'. Open
if ($parent && ($relation = self::getById($relationId)) && ($moduleName = \App\Module::getModuleName($relation['tabid']))) {
- 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 'clearCacheById'. Open
Cache::delete('getFieldsFromRelation', $relationId);
- 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 getById uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$row = [];
}
- 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\Cache' in method 'clearCacheByModule'. Open
Cache::delete('App\Relation::getByModule', $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 'App\Cache' in method 'clearCacheByModule'. Open
Cache::delete('HierarchyByRelation', '');
- 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 getByModule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$allRelations = [];
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
->from('vtiger_relatedlists')->innerJoin('vtiger_tab', 'vtiger_relatedlists.related_tabid = vtiger_tab.tabid')
->where(['vtiger_relatedlists.tabid' => Module::getModuleId($moduleName)])->orderBy(['sequence' => SORT_ASC])
- 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 assigning values to variables in if clauses and the like (line '150', column '63'). Open
public static function clearCacheById(int $relationId, bool $parent = true): void
{
if ($parent && ($relation = self::getById($relationId)) && ($moduleName = \App\Module::getModuleName($relation['tabid']))) {
self::clearCacheByModule($moduleName, false);
}
- 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\Cache' in method 'clearCacheById'. Open
Cache::delete('HierarchyByRelation', '');
- 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 'getByModule'. Open
->where(['vtiger_relatedlists.tabid' => Module::getModuleId($moduleName)])->orderBy(['sequence' => SORT_ASC])
- 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 'getByModule'. Open
if (Cache::has('App\Relation::getByModule', $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 'App\Cache' in method 'clearCacheById'. Open
Cache::delete('App\Relation::getById', $relationId);
- 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 "relation_id" 7 times. Open
$row['relation_id'] = (int) $row['relation_id'];
- 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 "favorites" 4 times. Open
$row['favorites'] = (int) $row['favorites'];
- 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 "relation_comment" 4 times. Open
$row['relation_comment'] = (int) $row['relation_comment'];
- 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 "sequence" 5 times. Open
->where(['vtiger_relatedlists.tabid' => Module::getModuleId($moduleName)])->orderBy(['sequence' => SORT_ASC])
- 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 "related_modulename" 3 times. Open
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- 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 "related_tabid" 4 times. Open
$row['related_tabid'] = (int) $row['related_tabid'];
- 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 "App\Relation::getById" 4 times. Open
if (Cache::has('App\Relation::getById', $relationId)) {
- 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 "tabid" 5 times. Open
$row['tabid'] = (int) $row['tabid'];
- 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 "creator_detail" 4 times. Open
$row['creator_detail'] = (int) $row['creator_detail'];
- 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 "App\Relation::getByModule" 4 times. Open
if (Cache::has('App\Relation::getByModule', $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 "presence" 4 times. Open
$row['presence'] = (int) $row['presence'];
- 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 "related_module_presence" 3 times. Open
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- 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 2 (key)
is int
but \App\Cache::delete()
takes string
defined at /code/app/Cache.php:105
Open
Cache::delete('App\Relation::getById', $relationId);
- Exclude checks
Doc-block of $relationId
in clearCacheById
contains phpdoc param type string
which is incompatible with the param type int
declared in the signature Open
* @param string $relationId
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Argument 2 (key)
is int
but \App\Cache::save()
takes string
defined at /code/app/Cache.php:89
Open
Cache::save('App\Relation::getById', $relationId, $row, Cache::LONG);
- Exclude checks
Argument 2 (key)
is int
but \App\Cache::delete()
takes string
defined at /code/app/Cache.php:105
Open
Cache::delete('getFieldsFromRelation', $relationId);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$row = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Argument 2 (key)
is int
but \App\Cache::has()
takes string
defined at /code/app/Cache.php:74
Open
if (Cache::has('App\Relation::getById', $relationId)) {
- Exclude checks
Argument 2 (key)
is int
but \App\Cache::get()
takes string
defined at /code/app/Cache.php:61
Open
return Cache::get('App\Relation::getById', $relationId);
- 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 getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
- 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
$row['tabid'] = (int) $row['tabid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['creator_detail'] = (int) $row['creator_detail'];
- 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 bool|null $onlyActive
- 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
->from('vtiger_relatedlists')->innerJoin('vtiger_tab', 'vtiger_relatedlists.related_tabid = vtiger_tab.tabid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['favorites'] = (int) $row['favorites'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allRelations = [];
- 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
$row['sequence'] = (int) $row['sequence'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
public static function getByModule(string $moduleName, ?bool $onlyActive = false, ?string $relatedModuleName = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
->where(['vtiger_relatedlists.tabid' => Module::getModuleId($moduleName)])->orderBy(['sequence' => SORT_ASC])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['relation_id'] = (int) $row['relation_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
$allRelations = Cache::get('App\Relation::getByModule', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['related_tabid'] = (int) $row['related_tabid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_relatedlists.tabid' => Module::getModuleId($moduleName)])->orderBy(['sequence' => SORT_ASC])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Cache::has('App\Relation::getByModule', $moduleName)) {
- Exclude checks
Line exceeds 120 characters; contains 172 characters Open
$dataReader = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
->from('vtiger_relatedlists')->innerJoin('vtiger_tab', 'vtiger_relatedlists.related_tabid = vtiger_tab.tabid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['presence'] = (int) $row['presence'];
- 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
* Get all relation for module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $relatedModuleName
- 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 ($allRelations as $relationId => $relations) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($relatedModuleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get relation by id.
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function clear cache by module name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $relationId
- 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::delete('App\Relation::getById', $relationId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::delete('HierarchyByRelation', '');
- 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('vtiger_relatedlists')->innerJoin('vtiger_tab', 'vtiger_relatedlists.related_tabid = vtiger_tab.tabid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['presence'] = (int) $row['presence'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = [];
- 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 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
}
- Exclude checks
Line exceeds 120 characters; contains 161 characters Open
$row = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['relation_id'] = (int) $row['relation_id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($fieldName) && $fieldName === $relation['field_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
{
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
if ($parent && ($relation = self::getById($relationId)) && ($moduleName = \App\Module::getModuleName($relation['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
* @param string $relModuleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getRelationId(string $moduleName, string $relModuleName, ?string $fieldName = null): ?int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function clear cache by 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
Cache::save('App\Relation::getByModule', $moduleName, $allRelations, Cache::LONG);
- 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::save('App\Relation::getById', $relationId, $row, Cache::LONG);
- 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 ($child) {
- 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
Cache::delete('App\Relation::getByModule', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_relatedlists.relation_id' => $relationId])->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
return $relationId;
- 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
public static function clearCacheByModule(string $moduleName, bool $child = true): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::getByModule($moduleName) as $relation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['relation_comment'] = (int) $row['relation_comment'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 !== $relations['related_module_presence']) {
- 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 getById(int $relationId): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $row;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get relation id by modules.
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($parent && ($relation = self::getById($relationId)) && ($moduleName = \App\Module::getModuleName($relation['tabid']))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::clearCacheByModule($moduleName, false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($allRelations[$relationId]);
- 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 (Cache::has('App\Relation::getById', $relationId)) {
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
->from('vtiger_relatedlists')->innerJoin('vtiger_tab', 'vtiger_relatedlists.related_tabid = vtiger_tab.tabid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['tabid'] = (int) $row['tabid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['sequence'] = (int) $row['sequence'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['creator_detail'] = (int) $row['creator_detail'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['relation_comment'] = (int) $row['relation_comment'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::getByModule($moduleName, true, $relModuleName) as $key => $relation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $child
- 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 ($allRelations as $relationId => $relations) {
- 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 bool $parent
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function clearCacheById(int $relationId, bool $parent = true): 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
if ($relatedModuleName !== $relations['related_modulename']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = (new Db\Query())->select(['vtiger_relatedlists.*', 'related_modulename' => 'vtiger_tab.name', 'related_module_presence' => 'vtiger_tab.presence'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $key;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($onlyActive) {
- 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
$relationId = 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
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $allRelations;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return Cache::get('App\Relation::getById', $relationId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['favorites'] = (int) $row['favorites'];
- 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
unset($allRelations[$relationId]);
- 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 $relationId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $fieldName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::delete('HierarchyByRelation', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allRelations[$row['relation_id']] = $row;
- 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['related_tabid'] = (int) $row['related_tabid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::clearCacheById($relation['relation_id'], false);
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationId = $relation['relation_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
Cache::delete('getFieldsFromRelation', $relationId);
- Exclude checks