SpeciesFileGroup/taxonworks

View on GitHub
app/models/concerns/shared/is_dwc_occurrence.rb

Summary

Maintainability
A
35 mins
Test Coverage

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

  def set_dwc_occurrence
    retried = false
    begin
      if dwc_occurrence_persisted?
        dwc_occurrence.generate_uuid_if_required # TODO: at some point when syncronized make this optional
Severity: Minor
Found in app/models/concerns/shared/is_dwc_occurrence.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

Avoid using touch because it skips validations.
Open

        dwc_occurrence.touch(:updated_at)

This cop checks for the use of methods which skip validations which are listed in https://guides.rubyonrails.org/active_record_validations.html#skipping-validations

Methods may be ignored from this rule by configuring a Whitelist.

Example:

# bad
Article.first.decrement!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active
product.touch
Billing.update_all("category = 'authorized', author = 'David'")
user.update_attribute(:website, 'example.com')
user.update_columns(last_request_at: Time.current)
Post.update_counters 5, comment_count: -1, action_count: 1

# good
user.update(website: 'example.com')
FileUtils.touch('file')

Example: Whitelist: ["touch"]

# bad
DiscussionBoard.decrement_counter(:post_count, 5)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active

# good
user.touch

Avoid using update_columns because it skips validations.
Open

        dwc_occurrence.update_columns(dwc_occurrence_attributes)

This cop checks for the use of methods which skip validations which are listed in https://guides.rubyonrails.org/active_record_validations.html#skipping-validations

Methods may be ignored from this rule by configuring a Whitelist.

Example:

# bad
Article.first.decrement!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active
product.touch
Billing.update_all("category = 'authorized', author = 'David'")
user.update_attribute(:website, 'example.com')
user.update_columns(last_request_at: Time.current)
Post.update_counters 5, comment_count: -1, action_count: 1

# good
user.update(website: 'example.com')
FileUtils.touch('file')

Example: Whitelist: ["touch"]

# bad
DiscussionBoard.decrement_counter(:post_count, 5)
DiscussionBoard.increment_counter(:post_count, 5)
person.toggle :active

# good
user.touch

TODO found
Open

    # TODO: do we need a ENV check option for disableing dwc_occurrence setting here as well?

TODO found
Open

      # TODO: semantics of these may need to be revisited, particularly updated_by_id

TODO found
Open

  # TODO: wrap in generic (reindex_dwc_occurrences method for use in InternalAttribute, TaxonDetermination, BiocurationClass and elsewhere)

TODO found
Open

        dwc_occurrence.generate_uuid_if_required # TODO: at some point when syncronized make this optional

TODO found
Open

    # TODO: why are extra queries fired if this is fired?

There are no issues that match your filters.

Category
Status