netzke/netzke-basepack

View on GitHub
lib/netzke/basepack/data_adapters/active_record_adapter.rb

Summary

Maintainability
F
3 days
Test Coverage

Method set_record_value_for_attribute has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def set_record_value_for_attribute(record, attr, value)
      value = value.to_time_in_current_zone if value.is_a?(Date) # convert Date to Time
      unless attr[:read_only]
        if attr[:setter]
          attr[:setter].call(record, value)
Severity: Minor
Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 5 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

Class ActiveRecordAdapter has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ActiveRecordAdapter < AbstractAdapter
    def self.for_class?(model)
      model && model <= ActiveRecord::Base
    end

Severity: Minor
Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 4 hrs to fix

    File active_record_adapter.rb has 347 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Netzke::Basepack::DataAdapters
      # Implementation of {Netzke::Basepack::DataAdapters::AbstractAdapter}
      class ActiveRecordAdapter < AbstractAdapter
        def self.for_class?(model)
          model && model <= ActiveRecord::Base
    Severity: Minor
    Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 4 hrs to fix

      Method record_value_for_attribute has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def record_value_for_attribute(r, a, through_association = false)
            v = if association_attr?(a)
              split = a[:name].to_s.split(/\.|__/)
              assoc = @model.reflect_on_association(split.first.to_sym)
              if through_association
      Severity: Minor
      Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 3 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 get_relation has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_relation(params = {})
            relation = @model.all
      
            query = params[:query]
      
      
      Severity: Minor
      Found in lib/netzke/basepack/data_adapters/active_record_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 combo_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def combo_data(attr, query = "")
            method, assoc = method_and_assoc(attr[:name])
      
            if assoc
              # Options for an asssociation attribute
      Severity: Minor
      Found in lib/netzke/basepack/data_adapters/active_record_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 set_record_value_for_attribute has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def set_record_value_for_attribute(record, attr, value)
            value = value.to_time_in_current_zone if value.is_a?(Date) # convert Date to Time
            unless attr[:read_only]
              if attr[:setter]
                attr[:setter].call(record, value)
      Severity: Minor
      Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 1 hr to fix

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

            def get_relation(params = {})
              relation = @model.all
        
              query = params[:query]
        
        
        Severity: Minor
        Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 1 hr to fix

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

              def record_value_for_attribute(r, a, through_association = false)
                v = if association_attr?(a)
                  split = a[:name].to_s.split(/\.|__/)
                  assoc = @model.reflect_on_association(split.first.to_sym)
                  if through_association
          Severity: Minor
          Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 1 hr to fix

            Avoid deeply nested control flow statements.
            Open

                            if assoc.macro == :has_one
                              assoc_instance = record.send(assoc.name)
                              if assoc_instance
                                assoc_instance.send("#{assoc_method}=", value)
                                assoc_instance.save # what should we do when this fails?..
            Severity: Major
            Found in lib/netzke/basepack/data_adapters/active_record_adapter.rb - About 45 mins to fix

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

                  def predicates_for_and_conditions(conditions)
                    return nil if conditions.empty?
              
                    predicates = conditions.map do |q|
                      q = HashWithIndifferentAccess.new(Netzke::Support.permit_hash_params(q))
              Severity: Minor
              Found in lib/netzke/basepack/data_adapters/active_record_adapter.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

              There are no issues that match your filters.

              Category
              Status