SpeciesFileGroup/taxonworks

View on GitHub
app/models/person.rb

Summary

Maintainability
F
5 days
Test Coverage

Method merge_with has a Cognitive Complexity of 148 (exceeds 5 allowed). Consider refactoring.
Open

  def merge_with(person_id)
    return false if person_id == id
    if r_person = Person.find(person_id) # get the new (merged into self) person
      begin
        ApplicationRecord.transaction do
Severity: Minor
Found in app/models/person.rb - About 3 days 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. [148/25]
Open

  def merge_with(person_id)
    return false if person_id == id
    if r_person = Person.find(person_id) # get the new (merged into self) person
      begin
        ApplicationRecord.transaction do
Severity: Minor
Found in app/models/person.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 merge_with has 148 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def merge_with(person_id)
    return false if person_id == id
    if r_person = Person.find(person_id) # get the new (merged into self) person
      begin
        ApplicationRecord.transaction do
Severity: Major
Found in app/models/person.rb - About 5 hrs to fix

    File person.rb has 340 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Person < ApplicationRecord
      include Housekeeping::Users
      include Housekeeping::Timestamps
      include Shared::AlternateValues
      include Shared::DataAttributes
    Severity: Minor
    Found in app/models/person.rb - About 4 hrs to fix

      Class Person has 28 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Person < ApplicationRecord
        include Housekeeping::Users
        include Housekeeping::Timestamps
        include Shared::AlternateValues
        include Shared::DataAttributes
      Severity: Minor
      Found in app/models/person.rb - About 3 hrs to fix

        Method bibtex_name has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def bibtex_name
            out = ''
        
            out << prefix + ' ' unless prefix.blank?
            out << last_name unless last_name.blank?
        Severity: Minor
        Found in app/models/person.rb - About 1 hr 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 parse_to_people has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.parse_to_people(name_string)
            parser(name_string).collect { |n| 
              Person::Unvetted.new(
                last_name: n['family'] ? NameCase(n['family']) : nil,
                first_name: n['given'] ? NameCase(n['given']) : nil,
        Severity: Minor
        Found in app/models/person.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 not_active_after_death has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def not_active_after_death
            unless is_editor? || is_author?
              errors.add(:year_active_start, 'is older than year of death') if year_active_start && year_died && year_active_start > year_died
              errors.add(:year_active_end, 'is older than year of death') if year_active_end && year_died && year_active_end > year_died
            end
        Severity: Minor
        Found in app/models/person.rb - About 45 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 deeply nested control flow statements.
        Open

                              if l_o.type == r_o.type &&
                                  l_o.alternate_value_object_attribute == r_o.alternate_value_object_attribute &&
                                  l_o.project_id == r_o.project_id
                                skip = true
                                break # stop looking in this bunch, if you found a match
        Severity: Major
        Found in app/models/person.rb - About 45 mins to fix

          Avoid more than 4 levels of block nesting.
          Open

                                if l_o.type == r_o.type &&
                                    l_o.alternate_value_object_attribute == r_o.alternate_value_object_attribute &&
                                    l_o.project_id == r_o.project_id
                                  skip = true
                                  break # stop looking in this bunch, if you found a match
          Severity: Minor
          Found in app/models/person.rb by rubocop

          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.

          Avoid more than 4 levels of block nesting.
          Open

                            if av.value == r_person.first_name
                              if av.type == 'AlternateValue::AlternateSpelling' &&
                                av.alternate_value_object_attribute == 'first_name' # &&
                                skip_av = true
                                break # stop looking in this bunch, if you found a match
          Severity: Minor
          Found in app/models/person.rb by rubocop

          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.

          Avoid more than 4 levels of block nesting.
          Open

                          AlternateValue::AlternateSpelling.create!(
                            alternate_value_object_type: 'Person',
                            value:  r_person.last_name,
                            alternate_value_object_attribute: 'last_name',
                            alternate_value_object_id: id) unless skip_av
          Severity: Minor
          Found in app/models/person.rb by rubocop

          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.

          Avoid more than 4 levels of block nesting.
          Open

                          AlternateValue::AlternateSpelling.create!(
                            alternate_value_object_type: 'Person',
                            value: r_person.first_name,
                            alternate_value_object_attribute: 'first_name',
                            alternate_value_object_id: id) unless skip_av
          Severity: Minor
          Found in app/models/person.rb by rubocop

          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.

          Avoid more than 4 levels of block nesting.
          Open

                            if av.value == r_person.last_name
                              if av.type == 'AlternateValue::AlternateSpelling' &&
                                  av.alternate_value_object_attribute == 'last_name' # &&
                                skip_av = true
                                break # stop looking in this bunch, if you found a match
          Severity: Minor
          Found in app/models/person.rb by rubocop

          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.

          TODO found
          Open

                    # TODO: handle prefix and suffix
          Severity: Minor
          Found in app/models/person.rb by fixme

          TODO found
          Open

                    # TODO: handle years attributes
          Severity: Minor
          Found in app/models/person.rb by fixme

          TODO found
          Open

            # TODO: remove this
          Severity: Minor
          Found in app/models/person.rb by fixme

          TODO found
          Open

            # TODO: deprecate this, always set explicitly
          Severity: Minor
          Found in app/models/person.rb by fixme

          TODO found
          Open

            # has_many :sources, through: :roles # TODO: test and confirm dependent
          Severity: Minor
          Found in app/models/person.rb by fixme

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

                          skip_av = false
                          av_list = l_person_hash['alternate values']
                          av_list ||= {}
                          av_list.each do |av|
                            if av.value == r_person.first_name
          Severity: Major
          Found in app/models/person.rb and 1 other location - About 1 hr to fix
          app/models/person.rb on lines 222..239

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

          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

                          skip_av = false
                          av_list = l_person_hash['alternate values']
                          av_list ||= {}
                          av_list.each do |av|
                            if av.value == r_person.last_name
          Severity: Major
          Found in app/models/person.rb and 1 other location - About 1 hr to fix
          app/models/person.rb on lines 194..211

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

          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 not_active_before_birth
              errors.add(:year_active_start, 'is younger than than year of birth') if year_active_start && year_born && year_active_start < year_born
              errors.add(:year_active_end, 'is younger than year of birth') if year_active_end && year_born && year_active_end < year_born
            end
          Severity: Minor
          Found in app/models/person.rb and 1 other location - About 15 mins to fix
          app/models/observation/sample.rb on lines 14..17

          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

          Use 2 (not 1) spaces for indentation.
          Open

               return false
          Severity: Minor
          Found in app/models/person.rb by rubocop

          This cops checks for indentation that doesn't use the specified number of spaces.

          See also the IndentationConsistency cop which is the companion to this one.

          Example:

          # bad
          class A
           def test
            puts 'hello'
           end
          end
          
          # good
          class A
            def test
              puts 'hello'
            end
          end

          Example: IgnoredPatterns: ['^\s*module']

          # bad
          module A
          class B
            def test
            puts 'hello'
            end
          end
          end
          
          # good
          module A
          class B
            def test
              puts 'hello'
            end
          end
          end

          There are no issues that match your filters.

          Category
          Status