SpeciesFileGroup/taxonworks

View on GitHub
lib/catalog/nomenclature/entry.rb

Summary

Maintainability
C
1 day
Test Coverage

Method has too many lines. [51/25]
Open

    def build
      v = object.valid_taxon_name
      base_names = v.historical_taxon_names

      base_names.each do |t|
Severity: Minor
Found in lib/catalog/nomenclature/entry.rb by rubocop

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

    def citations_with_names
      return @citations_with_names if !@citations_with_names.nil?

      d = Hash.new do |hash, key|
        hash[key] = []
Severity: Minor
Found in lib/catalog/nomenclature/entry.rb by rubocop

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 citations_with_names has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def citations_with_names
      return @citations_with_names if !@citations_with_names.nil?

      d = Hash.new do |hash, key|
        hash[key] = []
Severity: Minor
Found in lib/catalog/nomenclature/entry.rb - About 2 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 has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def build
      v = object.valid_taxon_name
      base_names = v.historical_taxon_names

      base_names.each do |t|
Severity: Major
Found in lib/catalog/nomenclature/entry.rb - About 2 hrs to fix

    Method citations_with_names has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def citations_with_names
          return @citations_with_names if !@citations_with_names.nil?
    
          d = Hash.new do |hash, key|
            hash[key] = []
    Severity: Minor
    Found in lib/catalog/nomenclature/entry.rb - About 1 hr to fix

      Method entry_item_matches_target? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def entry_item_matches_target?(item_object, reference_object)
            case item_object.class.to_s
            when 'Protonym'
              return item_object.id == reference_object.id
            when 'Combination'
      Severity: Minor
      Found in lib/catalog/nomenclature/entry.rb - About 55 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 build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def build
            v = object.valid_taxon_name
            base_names = v.historical_taxon_names
      
            base_names.each do |t|
      Severity: Minor
      Found in lib/catalog/nomenclature/entry.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 all_citations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def all_citations
            c  = items.collect{|i| i.citation}
      
            if !object.nil?
              relationship_items.each do |i|
      Severity: Minor
      Found in lib/catalog/nomenclature/entry.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 all_sources has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def all_sources
            s  = items.collect{|i| i.source}
            if !object.nil?
              relationship_items.each do |i|
                s << i.object.object_taxon_name.origin_citation.try(:source) if i.object.subject_taxon_name != object  # base_object?
      Severity: Minor
      Found in lib/catalog/nomenclature/entry.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 too many return statements within this method.
      Open

              return false
      Severity: Major
      Found in lib/catalog/nomenclature/entry.rb - About 30 mins to fix

        Do not use to_time on Date objects, because they know nothing about the time zone in use.
        Open

              items.sort{|a,b| [(a.nomenclature_date&.to_time || now), a.year_suffix.to_s + 'z', a.pages.to_s + 'z', a.object_class, a.base_object.cached_original_combination.to_s ] <=> [(b.nomenclature_date&.to_time || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] }
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by rubocop

        This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.

        Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.

        The cop also reports warnings when you are using to_time method, because it doesn't know about Rails time zone either.

        Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods today, current, yesterday, and tomorrow are prohibited and the usage of both to_time and 'totimeincurrentzone' are reported as warning.

        When EnforcedStyle is 'flexible' then only Date.today is prohibited and only to_time is reported as warning.

        Example: EnforcedStyle: strict

        # bad
        Date.current
        Date.yesterday
        Date.today
        date.to_time
        
        # good
        Time.zone.today
        Time.zone.today - 1.day

        Example: EnforcedStyle: flexible (default)

        # bad
        Date.today
        date.to_time
        
        # good
        Time.zone.today
        Time.zone.today - 1.day
        Date.current
        Date.yesterday
        date.in_time_zone

        Do not use to_time on Date objects, because they know nothing about the time zone in use.
        Open

              items.sort{|a,b| [(a.nomenclature_date&.to_time || now), a.year_suffix.to_s + 'z', a.pages.to_s + 'z', a.object_class, a.base_object.cached_original_combination.to_s ] <=> [(b.nomenclature_date&.to_time || now), b.year_suffix.to_s + 'z', b.pages.to_s + 'z', b.object_class, b.base_object.cached_original_combination.to_s ] }
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by rubocop

        This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.

        Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.

        The cop also reports warnings when you are using to_time method, because it doesn't know about Rails time zone either.

        Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods today, current, yesterday, and tomorrow are prohibited and the usage of both to_time and 'totimeincurrentzone' are reported as warning.

        When EnforcedStyle is 'flexible' then only Date.today is prohibited and only to_time is reported as warning.

        Example: EnforcedStyle: strict

        # bad
        Date.current
        Date.yesterday
        Date.today
        date.to_time
        
        # good
        Time.zone.today
        Time.zone.today - 1.day

        Example: EnforcedStyle: flexible (default)

        # bad
        Date.today
        date.to_time
        
        # good
        Time.zone.today
        Time.zone.today - 1.day
        Date.current
        Date.yesterday
        date.in_time_zone

        TODO found
        Open

              # TODO: Why aren't these first-class EntryItems? I think they should be.
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by fixme

        TODO found
        Open

              # TODO: Why aren't these first-class EntryItems?  I think they should be.
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by fixme

        TODO found
        Open

                    d[c.source].push trt.object_taxon_name # TODO: confirm
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by fixme

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

              ::TypeMaterial.where(protonym_id: all_protonyms.collect{|p| p.object}).all.
                each do |tm|
                  tm.citations.each do |c|
                    d[c.source].push tm.protonym
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb and 1 other location - About 15 mins to fix
        lib/catalog/nomenclature/entry.rb on lines 149..151

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

        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

              ::TaxonNameClassification.where(taxon_name_id: all_protonyms.collect{|p| p.object}).all.each do |tnc|
                tnc.citations.each do |c|
                  d[c.source].push tnc.taxon_name
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb and 1 other location - About 15 mins to fix
        lib/catalog/nomenclature/entry.rb on lines 162..165

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

        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

        Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.xmlschema, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.httpdate, Time.now.to_i, Time.now.to_f instead.
        Open

              now = Time.now
        Severity: Minor
        Found in lib/catalog/nomenclature/entry.rb by rubocop

        This cop checks for the use of Time methods without zone.

        Built on top of Ruby on Rails style guide (https://github.com/rubocop-hq/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/

        Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

        When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

        Example: EnforcedStyle: strict

        # `strict` means that `Time` should be used with `zone`.
        
        # bad
        Time.now
        Time.parse('2015-03-02 19:05:37')
        
        # bad
        Time.current
        Time.at(timestamp).in_time_zone
        
        # good
        Time.zone.now
        Time.zone.parse('2015-03-02 19:05:37')

        Example: EnforcedStyle: flexible (default)

        # `flexible` allows usage of `in_time_zone` instead of `zone`.
        
        # bad
        Time.now
        Time.parse('2015-03-02 19:05:37')
        
        # good
        Time.zone.now
        Time.zone.parse('2015-03-02 19:05:37')
        
        # good
        Time.current
        Time.at(timestamp).in_time_zone

        There are no issues that match your filters.

        Category
        Status