app/models/extended_content_parser.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for get_non_anonymous_key_value_pairs is too high. [29.48/15]
Open

  def self.get_non_anonymous_key_value_pairs(field_key, data)
    key_value_pairs = []

    return key_value_pairs if data.is_a?(String)

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 has too many lines. [24/10]
Open

  def self.attribute_pairs_to_process(item)
    # item.extended_content like this:
    #
    #   <creator xml_element_name="dc:creator"></creator>
    #   <creation_date xml_element_name="dc:date"></creation_date>

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 attribute_pairs_to_process is too high. [24.25/15]
Open

  def self.attribute_pairs_to_process(item)
    # item.extended_content like this:
    #
    #   <creator xml_element_name="dc:creator"></creator>
    #   <creation_date xml_element_name="dc:date"></creation_date>

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 has too many lines. [17/10]
Open

  def self.get_non_anonymous_key_value_pairs(field_key, data)
    key_value_pairs = []

    return key_value_pairs if data.is_a?(String)

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.

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

  def self.get_anonymous_key_value_pair(field_key, data)
    anonymous_fields = nil
    original_field_key = field_key.gsub(/_multiple/, '')

    if data.is_a?(String)

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.

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

  def self.flatten_any_extended_content_trees(data)
    # Example of what we might have in data at this point
    # {"xml_element_name"=>"dc:subject",
    #  "1"=>{"value"=>"Recreation", "label"=>"Sports & Recreation"},
    #  "2"=>"Festivals",

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.

Cyclomatic complexity for get_non_anonymous_key_value_pairs is too high. [7/6]
Open

  def self.get_non_anonymous_key_value_pairs(field_key, data)
    key_value_pairs = []

    return key_value_pairs if data.is_a?(String)

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for flatten_any_extended_content_trees is too high. [8/7]
Open

  def self.flatten_any_extended_content_trees(data)
    # Example of what we might have in data at this point
    # {"xml_element_name"=>"dc:subject",
    #  "1"=>{"value"=>"Recreation", "label"=>"Sports & Recreation"},
    #  "2"=>"Festivals",

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method flatten_any_extended_content_trees has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def self.flatten_any_extended_content_trees(data)
    # Example of what we might have in data at this point
    # {"xml_element_name"=>"dc:subject",
    #  "1"=>{"value"=>"Recreation", "label"=>"Sports & Recreation"},
    #  "2"=>"Festivals",
Severity: Minor
Found in app/models/extended_content_parser.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 get_non_anonymous_key_value_pairs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.get_non_anonymous_key_value_pairs(field_key, data)
    key_value_pairs = []

    return key_value_pairs if data.is_a?(String)

Severity: Minor
Found in app/models/extended_content_parser.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

Unused method argument - field_key. If it's necessary, use _ or _field_key as an argument name to indicate that it won't be used.
Open

  def self.get_non_anonymous_key_value_pairs(field_key, data)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Unused block argument - field_key. If it's necessary, use _ or _field_key as an argument name to indicate that it won't be used.
Open

        field_hash.reject do |field_key, field_data|

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Unused block argument - field_data. If it's necessary, use _ or _field_data as an argument name to indicate that it won't be used.
Open

      multi_instance_attributes = field_hash.select { |field_key, field_data| field_key =~ /_multiple$/  }

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Use only ascii symbols in comments.
Open

  #       "2"=>"Coupé"

This cop checks for non-ascii (non-English) characters in comments. You could set an array of allowed non-ascii chars in AllowedChars attribute (empty by default).

Example:

# bad
# Translates from English to 日本語。

# good
# Translates from English to Japanese

Use Hash#key? instead of Hash#has_key?.
Open

    if data.has_key?('value') && data.has_key?('circa')

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.
Open

    sorted_fields_with_position_hash = fields_with_position_hash.sort_by { |k, v| k.to_s }.to_h

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if data.has_key?('value') && data.has_key?('circa')

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Use Hash#key? instead of Hash#has_key?.
Open

    if data.has_key?('value') && data.has_key?('circa') && data['circa'] == '1'

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Use Hash#key? instead of Hash#has_key?.
Open

    if data.has_key?('value')

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Use Hash#key? instead of Hash#has_key?.
Open

    if data.has_key?('value') && data.has_key?('circa') && data['circa'] == '1'

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Use Hash#key? instead of Hash#has_key?.
Open

    if data.has_key?('value') && data.has_key?('circa')

This cop (by default) checks for uses of methods Hash#haskey? and Hash#hasvalue? where it enforces Hash#key? and Hash#value? It is configurable to enforce the inverse, using verbose method names also.

Example: EnforcedStyle: short (default)

# bad Hash#haskey? Hash#hasvalue?

# good Hash#key? Hash#value?

Example: EnforcedStyle: verbose

# bad Hash#key? Hash#value?

# good Hash#haskey? Hash#hasvalue?

Prefer single-quoted strings inside interpolations.
Open

        ":#{data_for_values.join(":")}:"

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Unused block argument - field_data. If it's necessary, use _ or _field_data as an argument name to indicate that it won't be used.
Open

      regular_attributes =        field_hash.reject { |field_key, field_data| field_key =~ /_multiple$/  }

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Unused block argument - index. If it's necessary, use _ or _index as an argument name to indicate that it won't be used.
Open

          field_data.map do |index, data|

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Unused block argument - v. If it's necessary, use _ or _v as an argument name to indicate that it won't be used.
Open

      data_for_values = data.reject { |k, v| k == 'xml_element_name' || k == 'label' }.values

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Do not use parallel assignment.
Open

      five_years_before, five_years_after = (data['value'].to_i - 5), (data['value'].to_i + 5)

Checks for simple usages of parallel assignment. This will only complain when the number of variables being assigned matched the number of assigning variables.

Example:

# bad
a, b, c = 1, 2, 3
a, b, c = [1, 2, 3]

# good
one, two = *foo
a, b = foo()
a, b = b, a

a = 1
b = 2
c = 3

There are no issues that match your filters.

Category
Status