SpeciesFileGroup/taxonworks

View on GitHub
lib/batch_load/import/taxon_names/castor_interpreter.rb

Summary

Maintainability
C
1 day
Test Coverage

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

    def build_taxon_names
      @total_data_lines = 0
      i = 0
      taxon_names = {}

Severity: Minor
Found in lib/batch_load/import/taxon_names/castor_interpreter.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 build_taxon_names has 93 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def build_taxon_names
      @total_data_lines = 0
      i = 0
      taxon_names = {}

Severity: Major
Found in lib/batch_load/import/taxon_names/castor_interpreter.rb - About 3 hrs to fix

    Method taxon_name_authors_attributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def taxon_name_authors_attributes(author_info)
          return [] if author_info.blank?
          multiple_author_query = 'and'
          multiple_author_index = author_info.index(multiple_author_query)
          split_author_info = multiple_author_index.nil? ? [author_info] : author_info.split(multiple_author_query)
    Severity: Minor
    Found in lib/batch_load/import/taxon_names/castor_interpreter.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

    Use delegate to define delegations.
    Open

        def parent_taxon_name_id

    This cop looks for delegations that could have been created automatically with the delegate method.

    Safe navigation &. is ignored because Rails' allow_nil option checks not just for nil but also delegates if nil responds to the delegated method.

    The EnforceForPrefixed option (defaulted to true) means that using the target object as a prefix of the method name without using the delegate method will be a violation. When set to false, this case is legal.

    Example:

    # bad
    def bar
      foo.bar
    end
    
    # good
    delegate :bar, to: :foo
    
    # good
    def bar
      foo&.bar
    end
    
    # good
    private
    def bar
      foo.bar
    end

    Example: EnforceForPrefixed: true (default)

    # bad
    def foo_bar
      foo.bar
    end
    
    # good
    delegate :bar, to: :foo, prefix: true

    Example: EnforceForPrefixed: false

    # good
    def foo_bar
      foo.bar
    end
    
    # good
    delegate :bar, to: :foo, prefix: true

    There are no issues that match your filters.

    Category
    Status