SpeciesFileGroup/taxonworks

View on GitHub
app/models/collection_object/dwc_extensions.rb

Summary

Maintainability
C
1 day
Test Coverage

File dwc_extensions.rb has 445 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module CollectionObject::DwcExtensions

  extend ActiveSupport::Concern

  include CollectionObject::DwcExtensions::TaxonworksExtensions
Severity: Minor
Found in app/models/collection_object/dwc_extensions.rb - About 6 hrs to fix

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

      def dwc_event_date
        return unless collecting_event
    
        %w{start_date end_date}
          .map { |d| %w{year month day}
    Severity: Minor
    Found in app/models/collection_object/dwc_extensions.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

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

      def dwc_event_time
        return unless collecting_event
    
        %w{start_time end_time}
          .map { |t| %w{hour minute second}
    Severity: Minor
    Found in app/models/collection_object/dwc_extensions.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 find_by instead of where.first.
    Open

        collecting_event.identifiers.where(type: 'Identifier::Local::TripCode').first&.cached

    This cop is used to identify usages of where.first and change them to use find_by instead.

    Example:

    # bad
    User.where(name: 'Bruce').first
    User.where(name: 'Bruce').take
    
    # good
    User.find_by(name: 'Bruce')

    TODO found
    Open

          # TODO: move to a proper extension(?)

    TODO found
    Open

          # TODO: move to a proper extension(?)

    TODO found
    Open

      # TODO: consider CVT attributes with Predicates linked to URIs

    TODO found
    Open

      # TODO: handle ranged lots

    TODO found
    Open

      # TODO: Expand to any GlobalIdentifier

    TODO found
    Open

      # TODO: extend to Georeferences when we understand how to describe spatial uncertainty

    TODO found
    Open

      # TODO: likeley a helper

    TODO found
    Open

      # TODO: consider CVT attributes with Predicates linked to URIs

    TODO found
    Open

      # TODO: Reconcile with Protocol (capital P) assignments

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

      def set_georeference_attributes
        case collecting_event&.dwc_georeference_source
        when :georeference
          collecting_event.preferred_georeference.dwc_georeference_attributes
        when :verbatim
    Severity: Major
    Found in app/models/collection_object/dwc_extensions.rb and 1 other location - About 1 hr to fix
    app/models/field_occurrence/dwc_extensions.rb on lines 136..162

    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 63.

    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

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

      def dwc_internal_attribute_for(target = :collection_object, dwc_term_name)
        return nil if dwc_term_name.nil?
    
        case target
        when  :collecting_event
    Severity: Major
    Found in app/models/collection_object/dwc_extensions.rb and 1 other location - About 1 hr to fix
    app/models/field_occurrence/dwc_extensions.rb on lines 281..297

    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 57.

    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 4 locations. Consider refactoring.
    Open

      def dwc_event_date
        return unless collecting_event
    
        %w{start_date end_date}
          .map { |d| %w{year month day}
    Severity: Major
    Found in app/models/collection_object/dwc_extensions.rb and 3 other locations - About 1 hr to fix
    app/models/collection_object/dwc_extensions.rb on lines 553..563
    app/models/field_occurrence/dwc_extensions.rb on lines 546..556
    app/models/field_occurrence/dwc_extensions.rb on lines 563..573

    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 47.

    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 4 locations. Consider refactoring.
    Open

      def dwc_event_time
        return unless collecting_event
    
        %w{start_time end_time}
          .map { |t| %w{hour minute second}
    Severity: Major
    Found in app/models/collection_object/dwc_extensions.rb and 3 other locations - About 1 hr to fix
    app/models/collection_object/dwc_extensions.rb on lines 570..580
    app/models/field_occurrence/dwc_extensions.rb on lines 546..556
    app/models/field_occurrence/dwc_extensions.rb on lines 563..573

    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 47.

    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

      def dwc_recorded_by
        v = nil
        if collecting_event
          v = collecting_event.collectors
            .order('roles.position')
    Severity: Minor
    Found in app/models/collection_object/dwc_extensions.rb and 1 other location - About 20 mins to fix
    app/models/field_occurrence/dwc_extensions.rb on lines 458..468

    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 27.

    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

      def dwc_higher_classification
        v = taxonomy.values.collect{|a| a.kind_of?(Array) ? a.second : a}
        v.shift
        v.pop
        v.compact
    Severity: Minor
    Found in app/models/collection_object/dwc_extensions.rb and 1 other location - About 15 mins to fix
    app/models/field_occurrence/dwc_extensions.rb on lines 388..393

    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 25.

    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

    There are no issues that match your filters.

    Category
    Status