lib/extended_content_helpers_for_test_set_up.rb

Summary

Maintainability
A
35 mins
Test Coverage

Method has too many lines. [16/10]
Open

  def create_and_map_extended_field_to_type(options = {})
    @should_create_extended_item = !options[:should_create_extended_item].nil? ? options.delete(:should_create_extended_item) : true

    # add a extended field to the base class or topic type in the case of topics
    create_extended_field(options)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for create_and_map_extended_field_to_type is too high. [18.47/15]
Open

  def create_and_map_extended_field_to_type(options = {})
    @should_create_extended_item = !options[:should_create_extended_item].nil? ? options.delete(:should_create_extended_item) : true

    # add a extended field to the base class or topic type in the case of topics
    create_extended_field(options)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

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

  def create_and_map_extended_field_to_type(options = {})
    @should_create_extended_item = !options[:should_create_extended_item].nil? ? options.delete(:should_create_extended_item) : true

    # add a extended field to the base class or topic type in the case of topics
    create_extended_field(options)
Severity: Minor
Found in lib/extended_content_helpers_for_test_set_up.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

Use the return of the conditional for variable assignment and comparison.
Open

    unless @base_class == 'Topic'
      @mapped_to_type_instance = ContentType.find_by_class_name(@base_class)
    else
      @mapped_to_type_instance = @extended_item.topic_type
    end

Do not use unless with else. Rewrite these with the positive case first.
Open

    unless @base_class == 'Topic'
      @mapping = @extended_field.content_type_to_field_mappings.last
    else
      @mapping = @extended_field.topic_type_to_field_mappings.last
    end

This cop looks for unless expressions with else clauses.

Example:

# bad
unless foo_bar.nil?
  # do something...
else
  # do a different thing...
end

# good
if foo_bar.present?
  # do something...
else
  # do a different thing...
end

Use the return of the conditional for variable assignment and comparison.
Open

    unless @base_class == 'Topic'
      @mapping = @extended_field.content_type_to_field_mappings.last
    else
      @mapping = @extended_field.topic_type_to_field_mappings.last
    end

Do not use unless with else. Rewrite these with the positive case first.
Open

    unless @base_class == 'Topic'
      @mapped_to_type_instance = ContentType.find_by_class_name(@base_class)
    else
      @mapped_to_type_instance = @extended_item.topic_type
    end

This cop looks for unless expressions with else clauses.

Example:

# bad
unless foo_bar.nil?
  # do something...
else
  # do a different thing...
end

# good
if foo_bar.present?
  # do something...
else
  # do a different thing...
end

There are no issues that match your filters.

Category
Status