YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebservicePremium/PrivilegeQuery.php

Summary

Maintainability
C
1 day
Test Coverage
F
46%

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();
        }
Severity: Minor
Found in api/webservice/WebservicePremium/PrivilegeQuery.php - About 7 hrs to fix

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();
        }
Severity: Major
Found in api/webservice/WebservicePremium/PrivilegeQuery.php - About 3 hrs to fix

    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)) {
    Severity: Major
    Found in api/webservice/WebservicePremium/PrivilegeQuery.php - About 1 hr to fix

      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();
              }

      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();
              }

      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)

      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.
           *

      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);

      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)

      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);

      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();

      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);

      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'));

      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'));
                  }

      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);

      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)) {

      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));

      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();
              }

      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'));

      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);

      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);

      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);

      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) ?? '';

      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) : '';

      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();
              }

      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);

      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) {

      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);

      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()))) {

      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'])) {

      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'])) {

      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;

      Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                                  $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      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'));

      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()))) {

      Call to undeclared method \App\Db\Query::andWhere
      Open

                  $query->andWhere(new Expression('0=1'));

      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));

      Call to method __construct from undeclared class \yii\db\Expression
      Open

                      $query->andWhere(new Expression('0=1'));

      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];

      Call to undeclared method \App\Db\Query::andWhere
      Open

                  $query->andWhere(new Expression('0=1'));

      Call to method __construct from undeclared class \yii\db\Expression
      Open

                  $query->andWhere(new Expression('0=1'));

      Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                      $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      Call to method getColumnName from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                      $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      Call to method clearFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                      $queryGenerator->clearFields()->setFields(['id']);

      Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                                  $queryGenerator = new \App\QueryGenerator($relModuleName);

      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');

      Call to method getCurrentUserModel from undeclared class \App\User (Did you mean class \Tests\App\User)
      Open

                  $user = \App\User::getCurrentUserModel();

      Argument 1 (recordId) is ?int but \App\Record::getType() takes int defined at /code/app/Record.php:279
      Open

              $parentModule = \App\Record::getType($parentId) ?? '';

      Reference to instance property permissions from undeclared class \App\QueryGenerator
      Open

                      $queryGenerator->permissions = false;

      Call to method has from undeclared class \App\User (Did you mean class \Tests\App\User)
      Open

              if (!$user->has('permission_type')) {

      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'));

      Call to method get from undeclared class \App\User (Did you mean class \Tests\App\User)
      Open

              switch ($user->get('permission_type')) {

      Checking instanceof against undeclared class \App\User (Did you mean class \Tests\App\User)
      Open

              if (!($user && $user instanceof \App\User)) {

      Call to method getColumnName from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
      Open

                                  $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      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];

      Call to method __construct from undeclared class \yii\db\Expression
      Open

                  $query->andWhere(new Expression('0=1'));

      Call to undeclared method \App\Db\Query::andWhere
      Open

              $query->andWhere($where);

      Call to undeclared method \App\Db\Query::andWhere
      Open

                      $query->andWhere(new Expression('0=1'));

      Avoid excessively long variable names like $relatedRecordModuleName. Keep variable name length under 20.
      Open

              $relatedRecordModuleName = $relatedRecord ? \App\Record::getType($relatedRecord) : '';

      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.

      Spaces must be used to indent lines; tabs are not allowed
      Open

              switch ($user->get('permission_type')) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $where[] = [$fieldInfo['tablename'] . '.' . $fieldInfo['columnname'] => 1];

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      break;

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $parentModule = \App\Record::getType($parentId) ?? '';

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param \App\Db\Query $query

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param mixed         $user

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param int           $relatedRecord

      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)

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      throw new \Api\Core\Exception('Invalid permissions ', 400);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $fieldInfo = \Api\Core\Module::getApiFieldPermission($moduleName, $user->get('permission_app'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @throws \Api\Core\Exception

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  case Privilege::USER_PERMISSIONS:

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $moduleModel = \Vtiger_Module_Model::getInstance($moduleName);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $where[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $parentId];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $where = ['and'];

      Spaces must be used to indent lines; tabs are not allowed
      Open

              } elseif ('ModComments' !== $moduleName) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  return;

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $relatedRecordModuleName = $relatedRecord ? \App\Record::getType($relatedRecord) : '';

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  case Privilege::ACCOUNTS_RELATED_RECORDS_AND_LOWER_IN_HIERARCHY:

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (0 === \App\ModuleHierarchy::getModuleLevel($moduleName)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              } elseif (\in_array($moduleName, ['Products', 'Services'])) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string        $moduleName

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $user = \App\User::getCurrentUserModel();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  case Privilege::ACCOUNTS_RELATED_RECORDS:

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $parentId = \App\Record::getParentRecord($user->get('permission_crmid'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  case Privilege::ACCOUNTS_RELATED_RECORDS_IN_HIERARCHY:

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      return \App\PrivilegeQuery::getPrivilegeQuery($query, $moduleName, $user, $relatedRecord);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!($user && $user instanceof \App\User)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(new Expression('0=1'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $parentId = \Api\WebservicePremium\Privilege::getParentCrmId($user);

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($fieldInfo) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!$user->has('permission_type')) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      break;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  default:

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $where[] = $whereOr;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              foreach ($relModuleModel->getReferenceFieldsForModule($parentModule) as $referenceField) {

      Line exceeds 120 characters; contains 170 characters
      Open

              } elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $relationModel = \Vtiger_Relation_Model::getInstanceById($relationId);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $queryGenerator->clearFields()->setFields(['id']);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      foreach ($fields as $fieldModel) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  } else {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  // exception

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          if (!$fieldModel->isActiveField()) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $where[] = $whereOr;

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($fields = $moduleModel->getFieldsByReference()) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $query->andWhere(new Expression('0=1'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $whereOr = ['or'];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $relationModel->set('parentRecord', \Vtiger_Record_Model::getInstanceById($parentId, $parentModule));

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              if ('Users' === $relModuleName || $relModuleName === $parentModule || $relModuleName === $moduleName) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  continue;

      Spaces must be used to indent lines; tabs are not allowed
      Open

              } elseif ('ModComments' !== $moduleName && $fieldsForParent = $moduleModel->getReferenceFieldsForModule($parentModule)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $queryGenerator->permissions = false;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  $queryGenerator->permissions = false;

      Line exceeds 120 characters; contains 129 characters
      Open

              } elseif ('ModComments' !== $moduleName && $fieldsForParent = $moduleModel->getReferenceFieldsForModule($parentModule)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $queryGenerator = $relationModel->getQuery();

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $whereOr[] = ["{$moduleModel->basetable}.{$moduleModel->basetableid}" => $subQuery];

      Line exceeds 120 characters; contains 127 characters
      Open

                              if ('Users' === $relModuleName || $relModuleName === $parentModule || $relModuleName === $moduleName) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $query->andWhere($where);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              $relModuleModel = \Vtiger_Module_Model::getInstance($relModuleName);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  $whereOr[] = ["{$fieldModel->getTableName()}.{$fieldModel->getColumnName()}" => $subQuery];

      Spaces must be used to indent lines; tabs are not allowed
      Open

              } elseif ($relatedRecord && (!$relatedRecordModuleName || !\App\Privilege::isPermitted($relatedRecordModuleName, 'DetailView', $relatedRecord, $user->getId()))) {

      Line exceeds 120 characters; contains 188 characters
      Open

              } elseif ((!$relatedRecord && !\in_array($moduleName, ['Products', 'Services'])) || (\in_array($relatedRecordModuleName, ['Products', 'Services']) && 'Documents' != $moduleName)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $query->andWhere(new Expression('0=1'));

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  $queryGenerator->setFields(['id'])->addCondition($referenceField->getName(), $parentId, 'eid');

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  foreach ($fieldsForParent as $referenceField) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          foreach ($fieldModel->getReferenceList() as $relModuleName) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $whereOr[] = ["{$referenceField->getTableName()}.{$referenceField->getColumnName()}" => $parentId];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $whereOr = ['or'];

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  foreach (array_keys(\App\Relation::getByModule($parentModule, true, $moduleName)) as $relationId) {

      Line exceeds 120 characters; contains 123 characters
      Open

                                  $queryGenerator->setFields(['id'])->addCondition($referenceField->getName(), $parentId, 'eid');

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (\count($whereOr) > 1) {

      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)) {

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              continue;

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  $queryGenerator = new \App\QueryGenerator($relModuleName);

      Spaces must be used to indent lines; tabs are not allowed
      Open

                                  $subQuery = $queryGenerator->createQuery()->select($queryGenerator->getColumnName('id'));

      There are no issues that match your filters.

      Category
      Status