bencao/acts_as_brand_new_copy

View on GitHub

Showing 5 of 7 total issues

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

    def calculate_save_order
      constraints, klasses = Set.new, Set.new
      traverse do |current_hash|
        klasses.add(current_hash['klass']) unless klasses.include?(current_hash['klass'])

Severity: Minor
Found in lib/acts_as_brand_new_copy/builder.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

Class Builder has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Builder
    def initialize(serialized_hash)
      @hash_origin  = serialized_hash
      @hash_copy    = JSON.parse(serialized_hash.to_json) # a way to do deep clone
      @save_order   = calculate_save_order
Severity: Minor
Found in lib/acts_as_brand_new_copy/builder.rb - About 2 hrs to fix

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

        def calculate_save_order
          constraints, klasses = Set.new, Set.new
          traverse do |current_hash|
            klasses.add(current_hash['klass']) unless klasses.include?(current_hash['klass'])
    
    
    Severity: Minor
    Found in lib/acts_as_brand_new_copy/builder.rb - About 1 hr to fix

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

        def sanitize_copy_param(name, param)
          return [] if param.nil?
      
          unless param.is_a?(Array)
            raise "#{name} param must be an array"
      Severity: Minor
      Found in lib/acts_as_brand_new_copy.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 copy_dependencies_for_join_type has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

                self_class,
                association_class,
                join_table_class,
                self_key_on_join_table,
                association_key_on_join_table
      Severity: Minor
      Found in lib/acts_as_brand_new_copy/serializer.rb - About 35 mins to fix
        Severity
        Category
        Status
        Source
        Language