YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.php

Summary

Maintainability
D
1 day
Test Coverage
F
0%

Function doTask has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        $fieldValueMapping = [];
        if (!empty($this->field_value_mapping)) {
            $fieldValueMapping = \App\Json::decode($this->field_value_mapping);
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.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 doTask has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        $fieldValueMapping = [];
        if (!empty($this->field_value_mapping)) {
            $fieldValueMapping = \App\Json::decode($this->field_value_mapping);
Severity: Major
Found in modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.php - About 2 hrs to fix

    Function setDataFromRequest has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setDataFromRequest(App\Request $request)
        {
            foreach ($this->getFieldNames() as $fieldName) {
                if ($request->has($fieldName)) {
                    switch ($fieldName) {
    Severity: Minor
    Found in modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.php - About 1 hr 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

    Function updateRecords has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        private function updateRecords($recordModel, $relatedData, $fieldValue)
        {
            $relatedModuleName = $relatedData[0];
            $relatedFieldName = $relatedData[1];
            $targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
    Severity: Minor
    Found in modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.php - About 1 hr 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 updateRecords has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function updateRecords($recordModel, $relatedData, $fieldValue)
        {
            $relatedModuleName = $relatedData[0];
            $relatedFieldName = $relatedData[1];
            $targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
    Severity: Minor
    Found in modules/com_vtiger_workflow/tasks/VTUpdateRelatedFieldTask.php - About 1 hr to fix

      The method doTask() has an NPath complexity of 432. The configured NPath complexity threshold is 200.
      Open

          public function doTask($recordModel)
          {
              $fieldValueMapping = [];
              if (!empty($this->field_value_mapping)) {
                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

      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 doTask() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
      Open

          public function doTask($recordModel)
          {
              $fieldValueMapping = [];
              if (!empty($this->field_value_mapping)) {
                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

      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 53 to the 15 allowed.
      Open

          public function doTask($recordModel)

      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

      Missing class import via use statement (line '46', column '44').
      Open

                              $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

      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

      Missing class import via use statement (line '48', column '28').
      Open

                              $exprEvaluater = new VTFieldExpressionEvaluater($expression);

      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

      Missing class import via use statement (line '46', column '21').
      Open

                              $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

      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

      Missing class import via use statement (line '46', column '72').
      Open

                              $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

      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\Json' in method 'setDataFromRequest'.
      Open

                              $value = \App\Json::encode($data);

      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 'doTask'.
      Open

                              $relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);

      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\Condition' in method 'doTask'.
      Open

                              if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {

      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\Json' in method 'doTask'.
      Open

                  $conditions = \App\Json::decode($this->conditions) ?: [];

      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\Log' in method 'doTask'.
      Open

                                  \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

      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 '111', column '50').
      Open

          private function updateRecords($recordModel, $relatedData, $fieldValue)
          {
              $relatedModuleName = $relatedData[0];
              $relatedFieldName = $relatedData[1];
              $targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);

      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 'doTask'.
      Open

                          if ($recordId && \App\Record::isExists($recordId)) {

      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 doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                              } else {
                                  \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
                              }

      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 'Vtiger_RelationListView_Model' in method 'updateRecords'.
      Open

              $targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);

      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\Json' in method 'updateRecords'.
      Open

              if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {

      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\Log' in method 'updateRecords'.
      Open

                      \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

      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\Json' in method 'setDataFromRequest'.
      Open

                              $values = \App\Json::decode($request->getRaw($fieldName));

      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\Log' in method 'doTask'.
      Open

                              \App\Log::warning('Record not found: ' . $recordId);

      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 doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                                  } else {
                                      $fieldValue = '0';
                                  }

      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 doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          $recordId = $recordModel->get($relatedData[0]);
                          if ($recordId && \App\Record::isExists($recordId)) {
                              $relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);
                              if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {

      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 updateRecords uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
                  }

      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\Condition' in method 'setDataFromRequest'.
      Open

                                  $condition = \App\Condition::getConditionsFromRequest($condition);

      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 setDataFromRequest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                              } else {
                                  $value = $request->getRaw($fieldName);
                              }

      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\Json' in method 'doTask'.
      Open

              if (!\App\Json::isEmpty($this->conditions)) {

      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 doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                          } else {
                              \App\Log::warning('Record not found: ' . $recordId);
                          }

      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\Json' in method 'updateRecords'.
      Open

      }

      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 '12').
      Open

          public function doTask($recordModel)
          {
              $fieldValueMapping = [];
              if (!empty($this->field_value_mapping)) {
                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

      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\Json' in method 'doTask'.
      Open

                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

      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\Json' in method 'setDataFromRequest'.
      Open

                                  $value = \App\Json::encode($values);

      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 'updateRecords'.
      Open

                  $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedModuleName);

      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 "fieldname" 3 times.
      Open

                          case 'fieldname':

      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.

      Avoid unused parameters such as '$recordModel'.
      Open

          public function getContents($recordModel)

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      Call to method warning from undeclared class \App\Log
      Open

                              \App\Log::warning('Record not found: ' . $recordId);

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

                  $queryGenerator->setConditions($conditions);

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

              $dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])

      Assigning true to property but \VTUpdateRelatedFieldTask->contents is \Vtiger_Record_Model
      Open

              $this->contents = true;

      Call to method warning from undeclared class \App\Log
      Open

                                  \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

      Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
      Open

                  $conditions = \App\Json::decode($this->conditions) ?: [];

      Reference to undeclared property \VTUpdateRelatedFieldTask->conditions (Did you mean $condition)
      Open

                      $this->{$fieldName} = $value;

      Reference to undeclared property \VTUpdateRelatedFieldTask->field_value_mapping (Did you mean $fieldValueMapping)
      Open

                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

      Call to method warning from undeclared class \App\Log
      Open

                      \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

      Declaration of function getContents(\Vtiger_Record_Model $recordModel) : bool should be compatible with function getContents(\Vtiger_Record_Model $recordModel) : \Vtiger_Record_Model defined in /code/modules/com_vtiger_workflow/VTTask.php:63
      Open

          public function getContents($recordModel)

      Reference to undeclared property \VTUpdateRelatedFieldTask->field_value_mapping (Did you mean $fieldValueMapping)
      Open

              if (!empty($this->field_value_mapping)) {

      Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
      Open

              if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {

      Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
      Open

              if (!\App\Json::isEmpty($this->conditions)) {

      Returning type \Vtiger_Record_Model but getContents() is declared to return bool
      Open

              return $this->contents;

      Each class must be in a namespace of at least one level (a top-level vendor name)
      Open

      class VTUpdateRelatedFieldTask extends VTTask

      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 12 and the first side effect is on line 10.
      Open

      <?php

      The 'getContents()' method which returns a boolean should be named 'is...()' or 'has...()'
      Open

          public function getContents($recordModel)
          {
              $this->contents = true;
      
              return $this->contents;

      BooleanGetMethodName

      Since: 0.2

      Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

      Example

      class Foo {
          /**
           * @return boolean
           */
          public function getFoo() {} // bad
          /**
           * @return bool
           */
          public function isFoo(); // ok
          /**
           * @return boolean
           */
          public function getFoo($bar); // ok, unless checkParameterizedMethods=true
      }

      Source https://phpmd.org/rules/naming.html#booleangetmethodname

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

          public $executeImmediately = false;

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

          /** {@inheritdoc} */

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

              return ['field_value_mapping', 'conditions'];

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

          public function getFieldNames()

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

              if (!empty($this->field_value_mapping)) {

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

                  $conditions = \App\Json::decode($this->conditions) ?: [];

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

                      }

      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

                      $fieldValue = trim($fieldInfo['value']);

      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

              $queryGenerator = $targetModel->getRelationQuery(true);

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

                              $data = $request->getArray($fieldName, \App\Purifier::TEXT);

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

                          case 'fieldname':

      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

                          if (!empty($fieldValue) || 0 == $fieldValue) {

      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 ($recordId && \App\Record::isExists($recordId)) {

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

          }

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

              $dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])

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

              while ($recordId = $dataReader->readColumn(0)) {

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

           *

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

                                  $value = \App\Json::encode($values);

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

                      }

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

           * Execute task.

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

          {

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

                  $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

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

              if (!\App\Json::isEmpty($this->conditions)) {

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

                      switch ($fieldInfo['valuetype']) {

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

                              require_once 'modules/com_vtiger_workflow/expression_engine/include.php';

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

                                      $fieldValue = '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

                      if (2 === \count($relatedData)) {

      Line exceeds 120 characters; contains 153 characters
      Open

                              if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {

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

                                      $relRecordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);

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

          private function updateRecords($recordModel, $relatedData, $fieldValue)

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

              $targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);

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

                          $recordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);

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

           */

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

                              $value = \App\Json::encode($data);

      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

                              }

      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 $this->contents;

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

           * Sets data from request.

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

           * @param App\Request $request

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

                  if ($request->has($fieldName)) {

      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

                          case 'expression':

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

                              $this->updateRecords($recordModel, $relatedData, $fieldValue);

      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

                              $relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);

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

                                  $fieldModel->getUITypeModel()->validate($fieldValue);

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

                                  $relRecordModel->set($relatedData[2], $fieldValue);

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

                                  if (false !== $relRecordModel->getPreviousValue($relatedData[2])) {

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

           * Function to get contents of this task.

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

           * @param Vtiger_Record_Model $recordModel

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

              }

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

                              $fieldValue = $recordModel->get($fieldValue);

      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

                                  \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

      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->setConditions($conditions);

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

              }

      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

                              if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {

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

                                  $fieldValue = $match[1];

      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

                              $fieldModel = $relRecordModel->getField($relatedData[2]);

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

                              \App\Log::warning('Record not found: ' . $recordId);

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

                  if ($fieldModel->isEditable()) {

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

                              break;

      Line exceeds 120 characters; contains 126 characters
      Open

                              $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

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

                              $exprEvaluater = new VTFieldExpressionEvaluater($expression);

      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

                  ->createCommand()->query();

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

                  $fieldModel = $recordModel->getField($relatedFieldName);

      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 ($this->getFieldNames() as $fieldName) {

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

                              $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

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

                              $fieldValue = $exprEvaluater->evaluate($recordModel);

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

                                  if ('true' == $fieldValue) {

      Line exceeds 120 characters; contains 128 characters
      Open

                                      $relRecordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);

      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

                  }

      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

                              break;

      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

                                      $fieldValue = '0';

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

                              if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {

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

                              if ($fieldModel->isEditable()) {

      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

           * @param string[]            $relatedData

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

              $relatedModuleName = $relatedData[0];

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

              $relatedFieldName = $relatedData[1];

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

                  return false;

      Line exceeds 120 characters; contains 122 characters
      Open

              $dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])

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

                      if (false !== $recordModel->getPreviousValue($relatedFieldName)) {

      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

                      \App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());

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

          public function setDataFromRequest(App\Request $request)

      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

                          $recordId = $recordModel->get($relatedData[0]);

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

                                      $relRecordModel->save();

      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 'field_value_mapping':

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

              }

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

           * @param string              $fieldValue

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

                  $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedModuleName);

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

          }

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

                                  $condition = \App\Condition::getConditionsFromRequest($condition);

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

           *

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

          public function doTask($recordModel)

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

                  foreach ($fieldValueMapping as $fieldInfo) {

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

                              $expression = $parser->expression();

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

              if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {

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

              $this->contents = true;

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

                      switch ($fieldName) {

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

                          case 'conditions':

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

                              foreach ($data as &$condition) {

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

                              $values = \App\Json::decode($request->getRaw($fieldName));

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

                              if (\is_array($values)) {

      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

                                  $value = $request->getRaw($fieldName);

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

                              $value = '';

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

                      $this->{$fieldName} = $value;

      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

              if (!$targetModel || !$targetModel->getRelationModel()) {

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

           * @param Vtiger_Record_Model $recordModel

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

           */

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

          public function getContents($recordModel)

      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 (!empty($fieldValueMapping)) {

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

           * Update related records by releted module.

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

           * @param Vtiger_Record_Model $recordModel

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

           *

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

                          $recordModel->save();

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

                      }

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

              $fieldValueMapping = [];

      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

                      $relatedData = explode('::', $fieldInfo['fieldname']);

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

           * @return bool

      Line exceeds 120 characters; contains 144 characters
      Open

              if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {

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

                      $fieldModel->getUITypeModel()->validate($fieldValue);

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

                      $recordModel->set($relatedFieldName, $fieldValue);

      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

           * @return bool contents

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

          /**

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

                              }

      There are no issues that match your filters.

      Category
      Status