Function getRelatedRecords
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public static function getRelatedRecords($record, $hierarchy)
{
$moduleName = Record::getType($record);
$records = $recordsLevel1 = $recordsLevel2 = [];
if (\in_array(0, $hierarchy)) {
- 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
File ModuleHierarchy.php
has 318 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace App;
/**
The class ModuleHierarchy has an overall complexity of 91 which is very high. The configured complexity threshold is 50. Open
class ModuleHierarchy
{
protected static $hierarchy;
protected static $modulesByLevels = [];
- Exclude checks
Function getChildModules
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function getChildModules($moduleName, $hierarchy = [1])
{
$modules = [];
switch (static::getModuleLevel($moduleName)) {
case 0:
- 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 getRelatedRecords
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getRelatedRecords($record, $hierarchy)
{
$moduleName = Record::getType($record);
$records = $recordsLevel1 = $recordsLevel2 = [];
if (\in_array(0, $hierarchy)) {
Function getQueriesForRelatedRecords
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function getQueriesForRelatedRecords(int $record, string $moduleName, array $hierarchy, Db\Query $subQuery = null): array
{
$modules = static::getChildModules($moduleName, $hierarchy);
$queries = [];
if ($modules) {
- 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 getChildModules
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getChildModules($moduleName, $hierarchy = [1])
{
$modules = [];
switch (static::getModuleLevel($moduleName)) {
case 0:
Function getModulesByUitype
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function getModulesByUitype($uitype)
{
switch ($uitype) {
case 67:
$level = 0;
- 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
Function getUitypeByModule
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function getUitypeByModule($moduleName)
{
switch (static::getModuleLevel($moduleName)) {
case 0:
$return = 67;
- 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
Function getMappingRelatedField
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function getMappingRelatedField($moduleName)
{
$return = false;
switch ((string) static::getModuleLevel($moduleName)) {
case '0':
- 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
Function getFieldsForListFilter
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function getFieldsForListFilter(string $moduleName): array
{
$fields = [];
$moduleId = \App\Module::getModuleId($moduleName);
foreach (static::getHierarchyByRelation() as $relations) {
- 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
Function accessModulesByLevel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function accessModulesByLevel($level = 0, $actionName = 'EditView')
{
$modules = [];
if (isset(static::$modulesByLevels[$level])) {
foreach (static::$modulesByLevels[$level] as $module => &$details) {
- 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 getRelatedRecords() has an NPath complexity of 456. The configured NPath complexity threshold is 200. Open
public static function getRelatedRecords($record, $hierarchy)
{
$moduleName = Record::getType($record);
$records = $recordsLevel1 = $recordsLevel2 = [];
if (\in_array(0, $hierarchy)) {
- 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 getRelatedRecords() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public static function getRelatedRecords($record, $hierarchy)
{
$moduleName = Record::getType($record);
$records = $recordsLevel1 = $recordsLevel2 = [];
if (\in_array(0, $hierarchy)) {
- 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
The method getChildModules() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function getChildModules($moduleName, $hierarchy = [1])
{
$modules = [];
switch (static::getModuleLevel($moduleName)) {
case 0:
- 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 29 to the 15 allowed. Open
public static function getRelatedRecords($record, $hierarchy)
- 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
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed. Open
public static function getChildModules($moduleName, $hierarchy = [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 getRelationFieldByHierarchy has a boolean flag argument $field, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getRelationFieldByHierarchy($moduleName, $field = 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
Missing class import via use statement (line '405', column '23'). Open
$dataReader = (new \App\Db\Query())
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class 'App\Field' in method 'getRelatedRecords'. Open
$fields = Field::getRelatedFieldForModule(false, $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\Privilege' in method 'accessModulesByParent'. Open
if (Privilege::isPermitted($module, $actionName) && isset($details['parentModule'])) {
- 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 'getFieldsForListFilter'. Open
$fields[$relation['field_name']][\App\Module::getModuleName($relation['tabid'])] = [$relation['rel_field_name'] => \App\Module::getModuleName($relation['rel_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\Module' in method 'init'. Open
if (Module::isModuleActive($module) && Privilege::isPermitted($module)) {
- 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\Record' in method 'getRelatedRecords'. Open
$moduleName = Record::getType($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\Cache' in method 'getHierarchyByRelation'. Open
Cache::save('HierarchyByRelation', '', $data, 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\Field' in method 'getQueriesForRelatedRecords'. Open
$fields = Field::getRelatedFieldForModule(false, $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\Privilege' in method 'init'. Open
if (Module::isModuleActive($module) && Privilege::isPermitted($module)) {
- 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 getHierarchyByRelation uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$data = [];
$dataReader = (new \App\Db\Query())
->select(['SR.tabid', 'SR.field_name', 'SR.related_tabid', 'rel_field_name' => 'RR.field_name', 'rel_tabid' => 'RR.tabid', 'a_yf_record_list_filter.*'])
->from('a_yf_record_list_filter')
- 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
The method getQueriesForRelatedRecords uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
}
- 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 'getHierarchyByRelation'. Open
if (Cache::has('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\Record' in method 'getQueryRelatedRecords'. Open
$moduleName = Record::getType($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\Module' in method 'getFieldsForListFilter'. Open
$fields[$relation['field_name']][\App\Module::getModuleName($relation['tabid'])] = [$relation['rel_field_name'] => \App\Module::getModuleName($relation['rel_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 'getHierarchyByRelation'. Open
$data = Cache::get('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\Field' in method 'getRelatedRecords'. Open
$fields = Field::getRelatedFieldForModule(false, $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\Module' in method 'getFieldsForListFilter'. Open
$moduleId = \App\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 assigning values to variables in if clauses and the like (line '225', column '9'). Open
public static function getChildModules($moduleName, $hierarchy = [1])
{
$modules = [];
switch (static::getModuleLevel($moduleName)) {
case 0:
- 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\Privilege' in method 'accessModulesByLevel'. Open
if (Privilege::isPermitted($module, $actionName)) {
- 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 "rel_field_name" 3 times. Open
if ($relation['related_tabid'] === $moduleId && !empty($relation['rel_field_name'])) {
- 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 "tablename" 3 times. Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
- 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 "HierarchyByRelation" 3 times. Open
if (Cache::has('HierarchyByRelation', '')) {
- 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 "parentModule" 3 times. Open
if (Privilege::isPermitted($module, $actionName) && isset($details['parentModule'])) {
- 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 "columnname" 3 times. Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
- 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 "modulesMapRelatedFields" 4 times. Open
if (false !== $field && isset(static::$hierarchy['modulesMapRelatedFields'][$moduleName][$field])) {
- 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 "modulesHierarchy" 5 times. Open
foreach (static::$hierarchy['modulesHierarchy'] as $module => $details) {
- 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 \App\Db\Query())
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
return $queryGenerator->createQuery()->column();
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setFields(['id']);
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setFields(['id']);
- Exclude checks
Call to method addNativeCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
- Exclude checks
Doc-block of $subQuery
in getQueriesForRelatedRecords
is phpdoc param type \App\Db\Query
which is not a permitted replacement of the nullable param type ?\App\Db\Query
declared in the signature ('?T' should be documented as 'T|null' or '?T') Open
* @param Db\Query $subQuery
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new QueryGenerator($field['name']);
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$tempQuery = $queryGenerator->createQuery();
- Exclude checks
Call to method addNativeCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new QueryGenerator($field['name']);
- Exclude checks
Call to method addNativeCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $subQuery]);
- Exclude checks
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 15 and the first side effect is on line 424. Open
<?php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (static::$hierarchy['modulesHierarchy'] as $module => $details) {
- 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 getModulesMapMMCustom($moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
case '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
if (isset(static::$hierarchy['modulesMap1M'][$moduleName])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getModulesByLevel($level = 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
foreach (static::$modulesByLevels[$level] as $module => &$details) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (static::$hierarchy['modulesHierarchy'] as $module => &$details) {
- 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 init()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getModulesHierarchy()
- 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 $uitype
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$level = 4;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
protected static $hierarchy;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(static::$hierarchy)) {
- 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 (Module::isModuleActive($module) && Privilege::isPermitted($module)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$hierarchy['modulesMap1M'][$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
return 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
switch ((string) static::getModuleLevel($moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '3':
- 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 145 characters Open
return isset(static::$hierarchy['modulesHierarchy'][$moduleName]) ? static::$hierarchy['modulesHierarchy'][$moduleName]['level'] : false;
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(static::$hierarchy['modulesMapMMBase'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$level = 0;
- 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
$modules = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 'subprocess_sl';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getModuleLevel($moduleName)
- 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
public static function getModulesByUitype($uitype)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 66:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 68:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$level = 3;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 'subprocess';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static $modulesByLevels = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(static::$hierarchy['modulesMapMMCustom'][$moduleName])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$modulesByLevels;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get modules list by uitype field.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($uitype) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Privilege::isPermitted($module, $actionName) && isset($details['parentModule'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules[$details['parentModule']][$module] = $details;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '4':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset(static::$modulesByLevels[$level])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$modulesByLevels[$level];
- 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
$level = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 65:
- 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 $modules[$parent];
- 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 = 'process';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$hierarchy['modulesHierarchy'];
- 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 isset(static::$hierarchy['modulesHierarchy'][$moduleName]) ? static::$hierarchy['modulesHierarchy'][$moduleName]['level'] : 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
public static function getModulesMapMMBase()
- 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
case 64:
- 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
case '0':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 'link';
- 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::$hierarchy['modulesMapMMCustom'][$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
return static::getModulesByLevel($level);
- 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 accessModulesByParent($parent, $actionName = 'EditView')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '2':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 'linkextend';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$hierarchy = require ROOT_DIRECTORY . '/app_data/moduleHierarchy.php';
- 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::$hierarchy['modulesMapMMBase'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $level) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 67:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$level = 2;
- 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 (isset(static::$modulesByLevels[$level])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules[$module] = $details;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getMappingRelatedField($moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$modulesByLevels[$details['level']][$module] = $details;
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getModulesMap1M($moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
{
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Privilege::isPermitted($module, $actionName)) {
- 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 accessModulesByLevel($level = 0, $actionName = 'EditView')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $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
}
- 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
$modules = static::getChildModules($moduleName, $hierarchy);
- 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
switch (static::getModuleLevel($moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = array_keys(static::getModulesByLevel(4));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($moduleName === $details['parentModule']) {
- 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
$fields = Field::getRelatedFieldForModule(false, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get related records by field.
- 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
$return = 67;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 64;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
public static function getRelatedRecords($record, $hierarchy)
- 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
$records = array_merge($records, $recordsLevel1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch (static::getModuleLevel($moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($is1Level && $isLevel4) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 2:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array(3, $hierarchy)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get related records by hierarchy.
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 0:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 2:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = array_keys(array_merge(static::getModulesByLevel(1), static::getModulesByLevel(4)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = array_keys(static::getModulesByLevel(3));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = static::getChildModules($moduleName, [1]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($field['name'], $modules)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsLevel2 = array_merge($recordsLevel2, $recordsByField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static function getRelatedRecordsByField($record, $field)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getUitypeByModule($moduleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 4:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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 child modules.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array(0, $hierarchy)) {
- 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 $field
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$is1Level = \in_array(1, $hierarchy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $level) {
- 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
$records = array_merge($records, $recordsByHierarchy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records = array_merge($records, $recordsLevel1);
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The function takes a hierarchy relationship.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$hierarchy['modulesMapRelatedFields'][$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
$return = 68;
- 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
$modules = array_keys(static::getModulesByLevel(1));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getRelationFieldByHierarchy($moduleName, $field = 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($field['name'], $modules)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 1:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($modules) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int[]
- 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
$modules[] = $mod;
- 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
$recordsLevel1 = array_merge($recordsLevel1, $recordsByField);
- 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 (isset(static::$hierarchy['modulesMapRelatedFields'][$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
case 3:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = 65;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int[] $hierarchy
- 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
case 0:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($is1Level) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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 ($fields as $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$level = static::getModuleLevel($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsByHierarchy = static::getRelatedRecords($record, $hierarchy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return array_unique($records);
- 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::$hierarchy['modulesMapRelatedFields'][$moduleName][$field];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($isLevel4) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordsLevel2 as $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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array(3, $hierarchy)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $field && isset(static::$hierarchy['modulesMapRelatedFields'][$moduleName][$field])) {
- 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 ($levelMod = static::getModulesByLevel(2)) {
- 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 array $hierarchy
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($modules) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsByField = static::getRelatedRecordsByField($record, $field);
- 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 = 66;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$isLevel4 = \in_array(4, $hierarchy);
- 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 ($levelMod as $mod => $details) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records = $recordsLevel1 = $recordsLevel2 = [];
- 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 (\in_array(2, $hierarchy)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = Field::getRelatedFieldForModule(false, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordsByField = static::getRelatedRecordsByField($record, $field);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getChildModules($moduleName, $hierarchy = [1])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 1:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
return $modules;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = Record::getType($record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records[] = $record;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!(0 == $level && !\in_array(1, $hierarchy))) {
- 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
* @param array $field
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setFields(['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
* @param string $moduleName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($subQuery) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Db\Query|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($queries[0]);
- 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 (static::getHierarchyByRelation() as $relations) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new QueryGenerator($field['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($modules) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = Field::getRelatedFieldForModule(false, $moduleName);
- 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 (0 === \count($queries)) {
- 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
foreach ($relations as $relation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['SR.tabid', 'SR.field_name', 'SR.related_tabid', 'rel_field_name' => 'RR.field_name', 'rel_tabid' => 'RR.tabid', 'a_yf_record_list_filter.*'])
- 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
$data[$row['relationid']][] = $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
return null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($queries as $query) {
- 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
public static function getHierarchyByRelation(int $relationId = null): 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
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $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
* @param int $record
- 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
private static function getQueriesForRelatedRecords(int $record, string $moduleName, array $hierarchy, Db\Query $subQuery = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery->union($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
* @param int|null $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
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $subQuery]);
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $subQuery]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queries[] = $tempQuery;
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
$queries = array_merge($queries, static::getQueriesForRelatedRecords($record, $field['name'], $hierarchy, clone $tempQuery));
- Exclude checks
Line exceeds 120 characters; contains 187 characters Open
$fields[$relation['field_name']][\App\Module::getModuleName($relation['tabid'])] = [$relation['rel_field_name'] => \App\Module::getModuleName($relation['rel_tabid'])];
- 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
* @param Db\Query $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
foreach ($fields as $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tempQuery = $queryGenerator->createQuery();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $queries;
- 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 array $hierarchy
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($relation['related_tabid'] === $moduleId && !empty($relation['rel_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
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
$modules = static::getChildModules($moduleName, $hierarchy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get related query by hierarchy.
- 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
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::save('HierarchyByRelation', '', $data, Cache::LONG);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $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
$fields = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields[$relation['field_name']][\App\Module::getModuleName($relation['tabid'])] = [$relation['rel_field_name'] => \App\Module::getModuleName($relation['rel_tabid'])];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $hierarchy
- 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
return $fields;
- 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
$queries = [];
- 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
$queries = array_merge($queries, static::getQueriesForRelatedRecords($record, $field['name'], $hierarchy, clone $tempQuery));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleId = \App\Module::getModuleId($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\Db\Query())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->leftJoin(['RR' => 'vtiger_relatedlists'], 'RR.relation_id=a_yf_record_list_filter.rel_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
*/
- 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
* Get hierarchy info by relation.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('a_yf_record_list_filter')
- 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 $queryGenerator->createQuery()->column();
- Exclude checks
Line exceeds 120 characters; contains 140 characters Open
private static function getQueriesForRelatedRecords(int $record, string $moduleName, array $hierarchy, Db\Query $subQuery = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($field['name'], $modules)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setFields(['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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = Record::getType($record);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queries = static::getQueriesForRelatedRecords($record, $moduleName, $hierarchy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $relationId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get array of queries. Quries are used to create union.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new QueryGenerator($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
$subQuery = $queries[0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $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
}
- 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
$data = Cache::get('HierarchyByRelation', '');
- Exclude checks
Line exceeds 120 characters; contains 168 characters Open
->select(['SR.tabid', 'SR.field_name', 'SR.related_tabid', 'rel_field_name' => 'RR.field_name', 'rel_tabid' => 'RR.tabid', 'a_yf_record_list_filter.*'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $data[$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
Line exceeds 120 characters; contains 123 characters Open
$queryGenerator->addNativeCondition([$field['tablename'] . '.' . $field['columnname'] => $record]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get fields for list filter.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getFieldsForListFilter(string $moduleName): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (Cache::has('HierarchyByRelation', '')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->leftJoin(['SR' => 'vtiger_relatedlists'], 'SR.relation_id=a_yf_record_list_filter.relationid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $data;
- 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 getQueryRelatedRecords(int $record, array $hierarchy): ?Db\Query
- Exclude checks