ForestAdmin/forest-rails

View on GitHub
app/services/forest_liana/schema_adapter.rb

Summary

Maintainability
F
3 days
Test Coverage
D
63%

File schema_adapter.rb has 481 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ForestLiana
  class SchemaAdapter
    def initialize(model)
      @model = model
    end
Severity: Minor
Found in app/services/forest_liana/schema_adapter.rb - About 7 hrs to fix

    Method add_validations has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_validations(column_schema, column)
          # NOTICE: Do not consider validations if a before_validation Active Records
          #         Callback is detected.
          if @model._validation_callbacks.map(&:kind).include? :before
            return column_schema
    Severity: Minor
    Found in app/services/forest_liana/schema_adapter.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

    Method add_columns has 114 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def add_columns
          @model.columns.each do |column|
            unless is_sti_column_of_child_model?(column)
              field_schema = get_schema_for_column(column)
              collection.fields << field_schema unless field_schema.nil?
    Severity: Major
    Found in app/services/forest_liana/schema_adapter.rb - About 4 hrs to fix

      Method add_validations has 82 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def add_validations(column_schema, column)
            # NOTICE: Do not consider validations if a before_validation Active Records
            #         Callback is detected.
            if @model._validation_callbacks.map(&:kind).include? :before
              return column_schema
      Severity: Major
      Found in app/services/forest_liana/schema_adapter.rb - About 3 hrs to fix

        Class SchemaAdapter has 24 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class SchemaAdapter
            def initialize(model)
              @model = model
            end
        
        
        Severity: Minor
        Found in app/services/forest_liana/schema_adapter.rb - About 2 hrs to fix

          Method add_columns has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              def add_columns
                @model.columns.each do |column|
                  unless is_sti_column_of_child_model?(column)
                    field_schema = get_schema_for_column(column)
                    collection.fields << field_schema unless field_schema.nil?
          Severity: Minor
          Found in app/services/forest_liana/schema_adapter.rb - 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

          Method perform has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def perform
                add_columns
                add_associations
          
                collection.fields.sort_by!.with_index { |k, idx| [k[:field].to_s, idx] }
          Severity: Minor
          Found in app/services/forest_liana/schema_adapter.rb - About 2 hrs to fix

            Method add_associations has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Invalid

                def add_associations
                  SchemaUtils.associations(@model).each do |association|
                    begin
                      if SchemaUtils.polymorphic?(association) &&
                        collection.fields << {
            Severity: Minor
            Found in app/services/forest_liana/schema_adapter.rb - About 1 hr to fix

              Method perform has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def perform
                    add_columns
                    add_associations
              
                    collection.fields.sort_by!.with_index { |k, idx| [k[:field].to_s, idx] }
              Severity: Minor
              Found in app/services/forest_liana/schema_adapter.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 add_associations has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def add_associations
                    SchemaUtils.associations(@model).each do |association|
                      begin
                        if SchemaUtils.polymorphic?(association) &&
                          collection.fields << {
              Severity: Minor
              Found in app/services/forest_liana/schema_adapter.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

              There are no issues that match your filters.

              Category
              Status