hnhdigital-os/laravel-model-change-tracking

View on GitHub
src/LogChangeTrait.php

Summary

Maintainability
C
1 day
Test Coverage

Method processManyToManyChange has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function processManyToManyChange($relation_method_name, $new_value, $override_relationship_method = null)
    {
        // The join between the model and the other model
        $relation = $this->$relation_method_name();

Severity: Major
Found in src/LogChangeTrait.php - About 2 hrs to fix

    Function bootLogChangeTrait has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function bootLogChangeTrait()
        {
            // Saved model event
            static::saved(function ($model) {
    
    
    Severity: Minor
    Found in src/LogChangeTrait.php - About 2 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

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

        private static function getModelChangeDiff($column_name, &$log_change, $old_text, $new_text)
        {
            if (is_array($old_text) && is_array($new_text)) {
                $difference = (new MapDiffer())->doDiff($old_text, $new_text);
    
    
    Severity: Minor
    Found in src/LogChangeTrait.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 bootLogChangeTrait has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function bootLogChangeTrait()
        {
            // Saved model event
            static::saved(function ($model) {
    
    
    Severity: Minor
    Found in src/LogChangeTrait.php - About 1 hr to fix

      Method getModelChangeDiff has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function getModelChangeDiff($column_name, &$log_change, $old_text, $new_text)
          {
              if (is_array($old_text) && is_array($new_text)) {
                  $difference = (new MapDiffer())->doDiff($old_text, $new_text);
      
      
      Severity: Minor
      Found in src/LogChangeTrait.php - About 1 hr to fix

        Method addModelChange has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                $model_id,
                $table_name,
                $column_name,
                $old_text,
                $new_text,
        Severity: Major
        Found in src/LogChangeTrait.php - About 50 mins to fix

          Function processManyToManyChange has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function processManyToManyChange($relation_method_name, $new_value, $override_relationship_method = null)
              {
                  // The join between the model and the other model
                  $relation = $this->$relation_method_name();
          
          
          Severity: Minor
          Found in src/LogChangeTrait.php - About 45 mins 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

          The method processManyToManyChange() has 103 lines of code. Current threshold is set to 100. Avoid really long methods.
          Open

              public function processManyToManyChange($relation_method_name, $new_value, $override_relationship_method = null)
              {
                  // The join between the model and the other model
                  $relation = $this->$relation_method_name();
          
          
          Severity: Minor
          Found in src/LogChangeTrait.php by phpmd

          Avoid assigning values to variables in if clauses and the like (line '131', column '39').
          Open

              public function processManyToManyChange($relation_method_name, $new_value, $override_relationship_method = null)
              {
                  // The join between the model and the other model
                  $relation = $this->$relation_method_name();
          
          
          Severity: Minor
          Found in src/LogChangeTrait.php by phpmd

          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 assigning values to variables in if clauses and the like (line '141', column '39').
          Open

              public function processManyToManyChange($relation_method_name, $new_value, $override_relationship_method = null)
              {
                  // The join between the model and the other model
                  $relation = $this->$relation_method_name();
          
          
          Severity: Minor
          Found in src/LogChangeTrait.php by phpmd

          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

          There are no issues that match your filters.

          Category
          Status