lib/workers/zoom_index_rebuild_worker.rb

Summary

Maintainability
F
3 days
Test Coverage

Method do_work has a Cognitive Complexity of 129 (exceeds 5 allowed). Consider refactoring.
Open

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0
Severity: Minor
Found in lib/workers/zoom_index_rebuild_worker.rb - About 2 days 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 do_work is too high. [167.7/15]
Open

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0

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

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0

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.

Class has too many lines. [190/100]
Open

class ZoomIndexRebuildWorker < BackgrounDRb::MetaWorker
  set_worker_name :zoom_index_rebuild_worker
  set_no_auto_load true

  # for prepare_to_zoom, etc.

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

Perceived complexity for do_work is too high. [53/7]
Open

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0

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

Cyclomatic complexity for do_work is too high. [48/6]
Open

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0

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 do_work has 160 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def do_work(args = nil)
    # start from scratch
    @last_id = nil
    @done = false
    @record_count = 0
Severity: Major
Found in lib/workers/zoom_index_rebuild_worker.rb - About 6 hrs to fix

    Block has too many lines. [91/25]
    Open

        classes_to_rebuild.each do |class_name|
          logger.info("Starting #{class_name}")
    
          @results[:current_zoom_class] = class_name
          cache[:results] = @results

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [55/25]
    Open

            the_class.find(:all, conditions: [clause, clause_values], limit: batch_size, order: 'id').each do |item|
              class_count_so_far += 1
              logger.info(item.id.to_s)
    
              if @skip_existing

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Avoid more than 3 levels of block nesting.
    Open

                  FileUtils.rm_r("#{Rails.root}/zebradb/private/data/#{class_name.tableize}", force: true) unless @skip_private

    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.

    TODO found
    Open

                  # TODO: more reporting on failed records?

    TODO found
    Open

              # TODO: skip the standard process startup lines, just grab errors

    TODO found
    Open

              # TODO: more reporting on failed records?

    TODO found
    Open

                  # TODO: skip the standard process startup lines, just grab errors

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                if @use_zebraidx
                  # trigger zebraidx and capture results for reporting
                  zebraidx_message = Rake::Task['zebra:index'].execute(ENV)
    
                  # rm data subdirectories now that we are done zebraidx batch processing
    Severity: Major
    Found in lib/workers/zoom_index_rebuild_worker.rb and 1 other location - About 1 hr to fix
    lib/workers/zoom_index_rebuild_worker.rb on lines 224..238

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 58.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if @use_zebraidx
              # trigger zebraidx and capture results for reporting
              zebraidx_message = Rake::Task['zebra:index'].execute(ENV)
    
              # rm data subdirectories now that we are done zebraidx batch processing
    Severity: Major
    Found in lib/workers/zoom_index_rebuild_worker.rb and 1 other location - About 1 hr to fix
    lib/workers/zoom_index_rebuild_worker.rb on lines 197..211

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 58.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    end at 57, 28 is not aligned with if at 50, 10.
    Open

                                end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Use @start_id.to_i.zero? instead of @start_id.to_i == 0.
    Open

        raise 'Start must be a valid item id number.' if @start_id != 'first' && @start_id.to_i == 0

    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 place comments on the same line as the end keyword.
    Open

          end # end batch

    This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

    Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

    Example:

    # bad
    if condition
      statement
    end # end if
    
    # bad
    class X # comment
      statement
    end
    
    # bad
    def x; end # comment
    
    # good
    if condition
      statement
    end
    
    # good
    class X # :nodoc:
      y
    end

    Use the_class_count.zero? instead of the_class_count == 0.
    Open

          if the_class_count == 0

    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

    end at 58, 25 is not aligned with if at 46, 6.
    Open

                             end

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Avoid rescuing without specifying an error class.
    Open

      rescue

    This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

    Example: EnforcedStyle: implicit

    # `implicit` will enforce using `rescue` instead of
    # `rescue StandardError`.
    
    # bad
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Example: EnforcedStyle: explicit (default)

    # `explicit` will enforce using `rescue StandardError`
    # instead of `rescue`.
    
    # bad
    begin
      foo
    rescue
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError
      bar
    end
    
    # good
    begin
      foo
    rescue OtherError
      bar
    end
    
    # good
    begin
      foo
    rescue StandardError, SecurityError
      bar
    end

    Use @end_id.to_i.zero? instead of @end_id.to_i == 0.
    Open

        raise 'End must be a valid item id number.' if @end_id != 'last' && @end_id.to_i == 0

    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

    Unreachable code detected.
    Open

            logger.info("Done with #{class_name}")

    This cop checks for unreachable code. The check are based on the presence of flow of control statement in non-final position in begin(implicit) blocks.

    Example:

    # bad
    
    def some_method
      return
      do_something
    end
    
    # bad
    
    def some_method
      if cond
        return
      else
        return
      end
      do_something
    end

    Example:

    # good
    
    def some_method
      do_something
    end

    Use class_count_so_far.positive? instead of class_count_so_far > 0.
    Open

            if class_count_so_far > 0

    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

    There are no issues that match your filters.

    Category
    Status