lib/search_dc_date_formulator.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Method format_date_from has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def format_date_from(dc_date)
      # if it's anything else, assume it's been formatted by another formulator
      return dc_date unless [Time, DateTime].include?(dc_date.class)
      # convert it to local time if the method is available (not available on dates < 1900)
      dc_date = dc_date.localtime if dc_date.respond_to?(:localtime)
Severity: Minor
Found in lib/search_dc_date_formulator.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

Assignment Branch Condition size for resolve_to_circa_if_present is too high. [23.62/15]
Open

    def resolve_to_circa_if_present(dc_dates)
      dates = []
      while dc_dates.size > 0 do
        date = dc_dates.shift
        # if we have a circa date, 2 dc:dates are added. One 5 years before, one 5 years after, and the
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

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

Assignment Branch Condition size for format_date_from is too high. [20.71/15]
Open

    def format_date_from(dc_date)
      # if it's anything else, assume it's been formatted by another formulator
      return dc_date unless [Time, DateTime].include?(dc_date.class)
      # convert it to local time if the method is available (not available on dates < 1900)
      dc_date = dc_date.localtime if dc_date.respond_to?(:localtime)
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

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. [14/10]
Open

    def format_date_from(dc_date)
      # if it's anything else, assume it's been formatted by another formulator
      return dc_date unless [Time, DateTime].include?(dc_date.class)
      # convert it to local time if the method is available (not available on dates < 1900)
      dc_date = dc_date.localtime if dc_date.respond_to?(:localtime)
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

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 format_date_from is too high. [9/6]
Open

    def format_date_from(dc_date)
      # if it's anything else, assume it's been formatted by another formulator
      return dc_date unless [Time, DateTime].include?(dc_date.class)
      # convert it to local time if the method is available (not available on dates < 1900)
      dc_date = dc_date.localtime if dc_date.respond_to?(:localtime)
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

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.

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

    def resolve_to_circa_if_present(dc_dates)
      dates = []
      while dc_dates.size > 0 do
        date = dc_dates.shift
        # if we have a circa date, 2 dc:dates are added. One 5 years before, one 5 years after, and the
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

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 resolve_to_circa_if_present has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def resolve_to_circa_if_present(dc_dates)
      dates = []
      while dc_dates.size > 0 do
        date = dc_dates.shift
        # if we have a circa date, 2 dc:dates are added. One 5 years before, one 5 years after, and the
Severity: Minor
Found in lib/search_dc_date_formulator.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 format_to_locales_specification has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def format_to_locales_specification(dc_dates)
      dates = []
      while dc_dates.size > 0 do
        date = dc_dates.shift
        if [Time, DateTime].include?(date.class)
Severity: Minor
Found in lib/search_dc_date_formulator.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

Avoid more than 3 levels of block nesting.
Open

        if ((dc_dates.size >= 2 && (date + 10.years).year == dc_dates[0].year && (date + 5.years).year == dc_dates[1].year) rescue false)
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid using rescue in its modifier form.
Open

        if ((dc_dates.size >= 2 && (date + 10.years).year == dc_dates[0].year && (date + 5.years).year == dc_dates[1].year) rescue false)
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

Use dc_dates.size.positive? instead of dc_dates.size > 0.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

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

        if [Time, DateTime].include?(date.class)
          dates << date.localtime.to_s(:long)
        else
          dates << date
        end
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

Do not use do with multi-line while.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

Checks for uses of do in multi-line while/until statements.

Example:

# bad
while x.any? do
  do_something(x.pop)
end

# good
while x.any?
  do_something(x.pop)
end

Example:

# bad
until x.empty? do
  do_something(x.pop)
end

# good
until x.empty?
  do_something(x.pop)
end

Use !empty? instead of size > 0.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

Use dc_dates.size.positive? instead of dc_dates.size > 0.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Do not use do with multi-line while.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

Checks for uses of do in multi-line while/until statements.

Example:

# bad
while x.any? do
  do_something(x.pop)
end

# good
while x.any?
  do_something(x.pop)
end

Example:

# bad
until x.empty? do
  do_something(x.pop)
end

# good
until x.empty?
  do_something(x.pop)
end

Use !empty? instead of size > 0.
Open

      while dc_dates.size > 0 do
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

Avoid using rescue in its modifier form.
Open

      dc_dates = dc_dates.collect { |date| date.to_time rescue date }
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

Avoid single-line method definitions.
Open

    def dc_date_separator; ', '; end
Severity: Minor
Found in lib/search_dc_date_formulator.rb by rubocop

This cop checks for single-line method definitions that contain a body. It will accept single-line methods with no body.

Example:

# bad
def some_method; body end
def link_to(url); {:name => url}; end
def @table.columns; super; end

# good
def no_op; end
def self.resource_class=(klass); end
def @table.columns; end

There are no issues that match your filters.

Category
Status