Function getConditions
has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
- 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 getConditions
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
Consider simplifying this complex logical expression. Open
if (0 === \App\ModuleHierarchy::getModuleLevel($moduleName)) {
$where[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $parentId];
} elseif (\in_array($moduleName, ['Products', 'Services'])) {
// exception
} elseif ('ModComments' !== $moduleName && $fieldsForParent = $moduleModel->getReferenceFieldsForModule($parentModule)) {
The method getConditions() has an NPath complexity of 16560. The configured NPath complexity threshold is 200. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
- 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 getConditions() has a Cyclomatic Complexity of 33. The configured cyclomatic complexity threshold is 10. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
- 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 49 to the 15 allowed. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The class PrivilegeQuery has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13. Open
class PrivilegeQuery
{
/**
* Function to check permission.
*
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Missing class import via use statement (line '51', column '15'). Open
throw new \Api\Core\Exception('Invalid permissions ', 400);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method getConditions has a boolean flag argument $user, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '101', column '30'). Open
$queryGenerator = new \App\QueryGenerator($relModuleName);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\App\User' in method 'getConditions'. Open
$user = \App\User::getCurrentUserModel();
- 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\PrivilegeQuery' in method 'getConditions'. Open
return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Api\Core\Module' in method 'getConditions'. Open
$fieldInfo = \Api\Core\Module::getApiFieldPermission($moduleName, $user->get('permission_app'));
- 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 getConditions uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$query->andWhere(new Expression('0=1'));
}
- 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 '\Api\WebservicePremium\Privilege' in method 'getConditions'. Open
$parentId = \Api\WebservicePremium\Privilege::getParentCrmId($user);
- 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\ModuleHierarchy' in method 'getConditions'. Open
if (0 === \App\ModuleHierarchy::getModuleLevel($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 '\Vtiger_Record_Model' in method 'getConditions'. Open
$relationModel->set('parentRecord', \Vtiger_Record_Model::getInstanceById($parentId, $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 assigning values to variables in if clauses and the like (line '71', column '46'). Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
- 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\Record' in method 'getConditions'. Open
$parentId = \App\Record::getParentRecord($user->get('permission_crmid'));
- 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\PrivilegeQuery' in method 'getConditions'. Open
return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Vtiger_Module_Model' in method 'getConditions'. Open
$relModuleModel = \Vtiger_Module_Model::getInstance($relModuleName);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Vtiger_Module_Model' in method 'getConditions'. Open
$moduleModel = \Vtiger_Module_Model::getInstance($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\Record' in method 'getConditions'. Open
$parentModule = \App\Record::getType($parentId) ?? '';
- 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 'getConditions'. Open
$relatedRecordModuleName = $relatedRecord ? \App\Record::getType($relatedRecord) : '';
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid assigning values to variables in if clauses and the like (line '90', column '8'). Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
{
if (!($user && $user instanceof \App\User)) {
$user = \App\User::getCurrentUserModel();
}
- 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 '\Vtiger_Relation_Model' in method 'getConditions'. Open
$relationModel = \Vtiger_Relation_Model::getInstanceById($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\Relation' in method 'getConditions'. Open
foreach (array_keys(\App\Relation::getByModule($parentModule, true, $moduleName)) as $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\PrivilegeQuery' in method 'getConditions'. Open
\App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Privilege' in method 'getConditions'. Open
} elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {
- 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 "Products" 3 times. Open
} elseif (\in_array($moduleName, ['Products', 'Services'])) {
- 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 "Services" 3 times. Open
} elseif (\in_array($moduleName, ['Products', 'Services'])) {
- 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.
Reference to instance property permissions
from undeclared class \App\QueryGenerator
Open
$queryGenerator->permissions = false;
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks
Call to method get
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$fieldInfo = \Api\Core\Module::getApiFieldPermission($moduleName, $user->get('permission_app'));
- Exclude checks
Call to method getId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
} elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Argument 1 (recordId)
is ?int
but \Vtiger_Record_Model::getInstanceById()
takes int
defined at /code/modules/Vtiger/models/Record.php:763
Open
$relationModel->set('parentRecord', \Vtiger_Record_Model::getInstanceById($parentId, $parentModule));
- Exclude checks
Call to method __construct
from undeclared class \yii\db\Expression
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Suspicious type false
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$where[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $parentId];
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Call to method __construct
from undeclared class \yii\db\Expression
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks
Call to method getColumnName
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks
Call to method clearFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->clearFields()->setFields(['id']);
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new \App\QueryGenerator($relModuleName);
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setFields(['id'])->addCondition($referenceField->getName(), $parentId, 'eid');
- Exclude checks
Call to method getCurrentUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$user = \App\User::getCurrentUserModel();
- Exclude checks
Argument 1 (recordId)
is ?int
but \App\Record::getType()
takes int
defined at /code/app/Record.php:279
Open
$parentModule = \App\Record::getType($parentId) ?? '';
- Exclude checks
Reference to instance property permissions
from undeclared class \App\QueryGenerator
Open
$queryGenerator->permissions = false;
- Exclude checks
Call to method has
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
if (!$user->has('permission_type')) {
- Exclude checks
Call to method get
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$parentId = \App\Record::getParentRecord($user->get('permission_crmid'));
- Exclude checks
Call to method get
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
switch ($user->get('permission_type')) {
- Exclude checks
Checking instanceof against undeclared class \App\User
(Did you mean class \Tests\App\User) Open
if (!($user && $user instanceof \App\User)) {
- Exclude checks
Call to method getColumnName
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks
Suspicious type false
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$whereOr[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $subQuery];
- Exclude checks
Call to method __construct
from undeclared class \yii\db\Expression
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere($where);
- Exclude checks
Call to undeclared method \App\Db\Query::andWhere
Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Avoid excessively long variable names like $relatedRecordModuleName. Keep variable name length under 20. Open
$relatedRecordModuleName = $relatedRecord ? \App\Record::getType($relatedRecord) : '';
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Spaces must be used to indent lines; tabs are not allowed Open
* Function to check permission.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($user->get('permission_type')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = [$fieldInfo['tablename'] . '.' . $fieldInfo['columnname'] => 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
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
\App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentModule = \App\Record::getType($parentId) ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Db\Query $query
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $user
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $relatedRecord
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getConditions(\App\Db\Query $query, string $moduleName, $user = false, $relatedRecord = null)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \Api\Core\Exception('Invalid permissions ', 400);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldInfo = \Api\Core\Module::getApiFieldPermission($moduleName, $user->get('permission_app'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- Exclude checks
Spaces must 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 Privilege::USER_PERMISSIONS:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $parentId];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where = ['and'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('ModComments' !== $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
$relatedRecordModuleName = $relatedRecord ? \App\Record::getType($relatedRecord) : '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case Privilege::ACCOUNTS_RELATED_RECORDS_AND_LOWER_IN_HIERARCHY:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === \App\ModuleHierarchy::getModuleLevel($moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (\in_array($moduleName, ['Products', 'Services'])) {
- 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
$user = \App\User::getCurrentUserModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case Privilege::ACCOUNTS_RELATED_RECORDS:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parentId = \App\Record::getParentRecord($user->get('permission_crmid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case Privilege::ACCOUNTS_RELATED_RECORDS_IN_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
return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!($user && $user instanceof \App\User)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->andWhere(new Expression('0=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
$parentId = \Api\WebservicePremium\Privilege::getParentCrmId($user);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldInfo) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$user->has('permission_type')) {
- 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
$where[] = $whereOr;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($relModuleModel->getReferenceFieldsForModule($parentModule) as $referenceField) {
- Exclude checks
Line exceeds 120 characters; contains 170 characters Open
} elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationModel = \Vtiger_Relation_Model::getInstanceById($relationId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->clearFields()->setFields(['id']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $fieldModel) {
- 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
// exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = $whereOr;
- Exclude checks
Spaces must 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 = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fields = $moduleModel->getFieldsByReference()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$whereOr = ['or'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationModel->set('parentRecord', \Vtiger_Record_Model::getInstanceById($parentId, $parentModule));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Users' === $relModuleName || $relModuleName === $parentModule || $relModuleName === $moduleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('ModComments' !== $moduleName && $fieldsForParent = $moduleModel->getReferenceFieldsForModule($parentModule)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->permissions = 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
$queryGenerator->permissions = false;
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
} elseif ('ModComments' !== $moduleName && $fieldsForParent = $moduleModel->getReferenceFieldsForModule($parentModule)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = $relationModel->getQuery();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$whereOr[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $subQuery];
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
if ('Users' === $relModuleName || $relModuleName === $parentModule || $relModuleName === $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
$query->andWhere($where);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relModuleModel = \Vtiger_Module_Model::getInstance($relModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$whereOr[] = ["{$fieldModel->getTableName()}.{$fieldModel->getColumnName()}" => $subQuery];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {
- Exclude checks
Line exceeds 120 characters; contains 188 characters Open
} elseif ((!$relatedRecord && !\in_array($moduleName, ['Products', 'Services'])) || (\in_array($relatedRecordModuleName, ['Products', 'Services']) && 'Documents' != $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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->andWhere(new Expression('0=1'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setFields(['id'])->addCondition($referenceField->getName(), $parentId, 'eid');
- Exclude checks
Spaces must 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 ($fieldsForParent as $referenceField) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fieldModel->getReferenceList() as $relModuleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$whereOr[] = ["{$referenceField->getTableName()}.{$referenceField->getColumnName()}" => $parentId];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$whereOr = ['or'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (array_keys(\App\Relation::getByModule($parentModule, true, $moduleName)) as $relationId) {
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$queryGenerator->setFields(['id'])->addCondition($referenceField->getName(), $parentId, 'eid');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\count($whereOr) > 1) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ((!$relatedRecord && !\in_array($moduleName, ['Products', 'Services'])) || (\in_array($relatedRecordModuleName, ['Products', 'Services']) && 'Documents' != $moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new \App\QueryGenerator($relModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));
- Exclude checks