indentlabs/notebook

View on GitHub
app/models/concerns/has_attributes.rb

Summary

Maintainability
D
1 day
Test Coverage

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

    def self.attribute_categories(user, show_hidden: false)
      # TODO: this is a code smell; we should probably either be whitelisting or fixing whatever is calling
      #       this with the wrong models
      return [] if ['attribute_category', 'attribute_field'].include?(content_name)

Severity: Minor
Found in app/models/concerns/has_attributes.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 attribute_categories has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.attribute_categories(user, show_hidden: false)
      # TODO: this is a code smell; we should probably either be whitelisting or fixing whatever is calling
      #       this with the wrong models
      return [] if ['attribute_category', 'attribute_field'].include?(content_name)

Severity: Major
Found in app/models/concerns/has_attributes.rb - About 2 hrs to fix

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

        def self.create_default_attribute_categories(user)
          # Don't create any attribute categories for AttributeCategories or AttributeFields that share the ContentController
          return [] if ['attribute_category', 'attribute_field'].include?(content_name)
    
          YAML.load_file(Rails.root.join('config', 'attributes', "#{content_name}.yml")).map do |category_name, defaults|
    Severity: Minor
    Found in app/models/concerns/has_attributes.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 universe_field_value has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def universe_field_value
          universe_field_cache = universe_field
          return nil unless self.respond_to?(:universe_id)
          return self.universe_id if universe_field_cache.nil?
    
    
    Severity: Minor
    Found in app/models/concerns/has_attributes.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 update_custom_attributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def update_custom_attributes
          (self.custom_attribute_values || []).each do |attribute|
            field = AttributeField.includes(:attribute_category).find_by(  # THIS GETS CALLED A TON
              name: attribute[:name],
              user: self.user,
    Severity: Minor
    Found in app/models/concerns/has_attributes.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 overview_field_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def overview_field_value(label)
          field_cache = overview_field(label)
          return nil if field_cache.nil?
    
          field_cache
    Severity: Minor
    Found in app/models/concerns/has_attributes.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 name_field_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def name_field_value
          @name_field_lookup_cache ||= {}
          cache_key = "#{self.class.name}-#{self.id.to_s}"
    
          if @name_field_lookup_cache.key?(cache_key)
    Severity: Minor
    Found in app/models/concerns/has_attributes.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 get_field_value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_field_value(category, field, fallback=nil)
          category = AttributeCategory.find_by(
            label:       category,
            entity_type: self.class.name.downcase,
            user_id:     self.user_id,
    Severity: Minor
    Found in app/models/concerns/has_attributes.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