opf/openproject

View on GitHub
app/models/journable/historic_active_record_relation.rb

Summary

Maintainability
D
2 days
Test Coverage

Method modify_conditions has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

  def modify_conditions(node)
    if node.kind_of? Arel::TreeManager
      # We have another sub-tree, investigate its core, which is a SelectCore
      node.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
        modify_conditions(core)
Severity: Minor
Found in app/models/journable/historic_active_record_relation.rb - About 6 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

File historic_active_record_relation.rb has 332 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
  attr_accessor :timestamp

  include ActiveRecord::Delegation::ClassSpecificRelation

Severity: Minor
Found in app/models/journable/historic_active_record_relation.rb - About 4 hrs to fix

    Class HistoricActiveRecordRelation has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
      attr_accessor :timestamp
    
      include ActiveRecord::Delegation::ClassSpecificRelation
    
    
    Severity: Minor
    Found in app/models/journable/historic_active_record_relation.rb - About 2 hrs to fix

      Method modify_conditions has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def modify_conditions(node)
          if node.kind_of? Arel::TreeManager
            # We have another sub-tree, investigate its core, which is a SelectCore
            node.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
              modify_conditions(core)
      Severity: Major
      Found in app/models/journable/historic_active_record_relation.rb - About 2 hrs to fix

        Method substitute_database_table_in_predicate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def substitute_database_table_in_predicate(predicate)
            case predicate
            when String
              gsub_table_names_in_sql_string!(predicate)
            when Arel::Nodes::HomogeneousIn,
        Severity: Minor
        Found in app/models/journable/historic_active_record_relation.rb - About 1 hr to fix

          Method modify_joins has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def modify_joins(arel)
              arel.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
                core.instance_variable_get(:@source).right.each do |node|
                  if node.kind_of? Arel::Nodes::StringJoin
                    gsub_table_names_in_sql_string!(node.left)
          Severity: Minor
          Found in app/models/journable/historic_active_record_relation.rb - 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 substitute_database_table_in_predicate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def substitute_database_table_in_predicate(predicate)
              case predicate
              when String
                gsub_table_names_in_sql_string!(predicate)
              when Arel::Nodes::HomogeneousIn,
          Severity: Minor
          Found in app/models/journable/historic_active_record_relation.rb - About 55 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

          Avoid deeply nested control flow statements.
          Open

                  if node.name == "id"
                    # ID needs to be pulled from the Journal table
                    node.relation = Journal.arel_table
                    node.name = "journable_id"
                  else
          Severity: Major
          Found in app/models/journable/historic_active_record_relation.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                elsif node.kind_of? Arel::Nodes::NodeExpression
                  # Generic case, go through left and right
                  modify_conditions(node.left) if node.respond_to?(:left) && node.left
                  modify_conditions(node.right) if node.respond_to?(:right) && node.right
            Severity: Major
            Found in app/models/journable/historic_active_record_relation.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                    if node.left == model.arel_table
                      node.left = model.journal_class.arel_table
                    end
              Severity: Major
              Found in app/models/journable/historic_active_record_relation.rb - About 45 mins to fix

                Method modify_order_clauses has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def modify_order_clauses(arel)
                    arel.instance_variable_get(:@ast).instance_variable_get(:@orders).each do |order_clause|
                      if order_clause.kind_of? Arel::Nodes::SqlLiteral
                        gsub_table_names_in_sql_string!(order_clause)
                      elsif order_clause.expr.relation == model.arel_table
                Severity: Minor
                Found in app/models/journable/historic_active_record_relation.rb - About 35 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

                Method pluck has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def pluck(*column_names)
                    column_names.map! do |column_name|
                      case column_name
                      when :id, "id"
                        "journals.journable_id"
                Severity: Minor
                Found in app/models/journable/historic_active_record_relation.rb - About 25 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

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        if order_clause.kind_of? Arel::Nodes::SqlLiteral
                          gsub_table_names_in_sql_string!(order_clause)
                        elsif order_clause.expr.relation == model.arel_table
                          if order_clause.expr.name == "id"
                            order_clause.expr.name = "journable_id"
                Severity: Minor
                Found in app/models/journable/historic_active_record_relation.rb and 1 other location - About 40 mins to fix
                app/models/journable/historic_active_record_relation.rb on lines 332..341

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 37.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                      if order_clause.kind_of? Arel::Nodes::SqlLiteral
                        gsub_table_names_in_sql_string!(order_clause)
                      elsif order_clause.expr.relation == model.arel_table
                        if order_clause.expr.name == "id"
                          order_clause.expr.name = "journable_id"
                Severity: Minor
                Found in app/models/journable/historic_active_record_relation.rb and 1 other location - About 40 mins to fix
                app/models/journable/historic_active_record_relation.rb on lines 390..399

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 37.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status