khiav223577/active_model_cachers

View on GitHub

Showing 8 of 10 total issues

Method define_callback_for_cleaning_cache has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

      def define_callback_for_cleaning_cache(class_name, column, foreign_key, with_id, on: nil)
        return if @callbacks_defined
        @callbacks_defined = true

        clean = ->(id){ clean_at(with_id ? id : nil) }
Severity: Minor
Found in lib/active_model_cachers/cache_service.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 exec_by has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def exec_by(attr, primary_key, service_klasses, method, data: nil)
        bindings = [@model]
        reflects = (attr.belongs_to? ? [] : [attr.reflect])
        if @model and attr.association?
          if attr.belongs_to? and method != :clean_cache # no need to load binding when just cleaning cache
Severity: Minor
Found in lib/active_model_cachers/active_record/cacher.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 query_association has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def query_association(binding, id)
        return binding.association(@column).load_target if binding.is_a?(::ActiveRecord::Base)
        id = @reflect.active_record.where(id: id).limit(1).pluck(foreign_key).first if foreign_key != 'id'
        case
        when collection? ; return id ? @reflect.klass.where(@reflect.foreign_key => id).to_a : []
Severity: Minor
Found in lib/active_model_cachers/active_record/attr_model.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 cache_at has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def cache_at(column, query = nil, expire_by: nil, on: nil, foreign_key: nil, primary_key: nil)
        attr = AttrModel.new(self, column, foreign_key: foreign_key, primary_key: primary_key)
        return cache_belongs_to(attr) if attr.belongs_to?

        loaded = false
Severity: Minor
Found in lib/active_model_cachers/active_record/extension.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

Method add has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def add(object, class_name, id, foreign_key, model)
Severity: Minor
Found in lib/active_model_cachers/column_value_cache.rb - About 35 mins to fix

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

        def get_without_cache(binding, attr)
          query = get_query(binding, attr)
          return binding ? binding.instance_exec(@id, &query) : query.call(@id) if @id and query.parameters.size == 1
          return binding ? binding.instance_exec(&query) : query.call
        end
    Severity: Minor
    Found in lib/active_model_cachers/cache_service.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 foreign_key has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def foreign_key(reverse: false)
            return @foreign_key if @foreign_key
            return if not association?
            # key may be symbol if specify foreign_key in association options
            return @reflect.chain.last.foreign_key.to_s if reverse and join_table
    Severity: Minor
    Found in lib/active_model_cachers/active_record/attr_model.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

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

        def new_constants_in(*)
          new_constants = super.each do |const_name|
            hooks = load_hooks[const_name]
            need_compact = false
            hooks.each_with_index do |hook, idx|
    Severity: Minor
    Found in lib/active_model_cachers/hook/dependencies.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

    Severity
    Category
    Status
    Source
    Language