SpeciesFileGroup/taxonworks

View on GitHub
app/helpers/plugins/papertrail_helper.rb

Summary

Maintainability
C
1 day
Test Coverage

Method get_diffs has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

  def get_diffs version_new, version_old
    added_strings = []
    added_strings_indices = []
    deleted_strings = []
    deleted_strings_indices = []
Severity: Minor
Found in app/helpers/plugins/papertrail_helper.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 has too many lines. [52/25]
Open

  def get_diffs version_new, version_old
    added_strings = []
    added_strings_indices = []
    deleted_strings = []
    deleted_strings_indices = []

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. [29/25]
Open

  def get_diffs_date version_new, version_old
    added_strings = []
    added_strings_indices = []
    deleted_strings = []
    deleted_strings_indices = []

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

  def get_diffs version_new, version_old
    added_strings = []
    added_strings_indices = []
    deleted_strings = []
    deleted_strings_indices = []
Severity: Major
Found in app/helpers/plugins/papertrail_helper.rb - About 2 hrs to fix

    Method get_diffs_date has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def get_diffs_date version_new, version_old
        added_strings = []
        added_strings_indices = []
        deleted_strings = []
        deleted_strings_indices = []
    Severity: Minor
    Found in app/helpers/plugins/papertrail_helper.rb - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  if new_index_new > version_new.length || version_old[new_index_old] == version_new[new_index_new]
                    if curr_index_new != new_index_new
                      added_strings.push(version_new[curr_index_new...new_index_new])
                      added_strings_indices.push(curr_index_new)
                    end
      Severity: Major
      Found in app/helpers/plugins/papertrail_helper.rb - About 45 mins to fix

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

          def get_diffs_date version_new, version_old
            added_strings = []
            added_strings_indices = []
            deleted_strings = []
            deleted_strings_indices = []
        Severity: Minor
        Found in app/helpers/plugins/papertrail_helper.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 get_highlighted_words has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def get_highlighted_words words, highlighted_words, highlighted_words_indices, style_class
            start_index = 0
            end_index = 0
            html_string = ''
        
        
        Severity: Minor
        Found in app/helpers/plugins/papertrail_helper.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

                  while new_index_old < version_old.length
                    if new_index_new > version_new.length || version_old[new_index_old] == version_new[new_index_new]
                      if curr_index_new != new_index_new
                        added_strings.push(version_new[curr_index_new...new_index_new])
                        added_strings_indices.push(curr_index_new)

        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.

        Tagging a string as html safe may be a security risk.
        Open

            return html_string.html_safe

        This cop checks for the use of output safety calls like html_safe, raw, and safe_concat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

        Example:

        user_content = "hi"
        
        # bad
        "

        #{user_content}

        ".html_safe # => ActiveSupport::SafeBuffer "

        hi

        " # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

        <b>hi</b>

        " # bad out = "" out << "
      • #{user_content}
      • " out << "
      • #{user_content}
      • " out.html_safe # => ActiveSupport::SafeBuffer "
      • hi
      • hi
      • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
      • <b>hi</b>
      • <b>hi</b>
      • " # bad out = "

        trusted content

        ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

        trusted_content

        hi" # good out = "

        trusted content

        ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

        trusted_content

        <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

        Prefer symbols instead of strings as hash keys.
        Open

              'added_strings_indices' => added_strings_indices, 

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'deleted_strings' => deleted_strings,

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'deleted_strings' => deleted_strings,

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'deleted_strings_indices' => deleted_strings_indices

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'deleted_strings_indices' => deleted_strings_indices

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'added_strings' => added_strings,

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'added_strings_indices' => added_strings_indices, 

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        Prefer symbols instead of strings as hash keys.
        Open

              'added_strings' => added_strings,

        This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

        Example:

        # bad
        { 'one' => 1, 'two' => 2, 'three' => 3 }
        
        # good
        { one: 1, two: 2, three: 3 }

        There are no issues that match your filters.

        Category
        Status