SpeciesFileGroup/taxonworks

View on GitHub
app/models/combination.rb

Summary

Maintainability
D
1 day
Test Coverage

File combination.rb has 302 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Combination < TaxonName

  # The ranks that can be used to build combinations. ! TODO:  family group names 
  APPLICABLE_RANKS = %w{family subfamily tribe subtribe genus subgenus section subsection
                        series subseries species subspecies variety subvariety form subform}.freeze
Severity: Minor
Found in app/models/combination.rb - About 3 hrs to fix

    Class Combination has 27 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Combination < TaxonName
    
      # The ranks that can be used to build combinations. ! TODO:  family group names 
      APPLICABLE_RANKS = %w{family subfamily tribe subtribe genus subgenus section subsection
                            series subseries species subspecies variety subvariety form subform}.freeze
    Severity: Minor
    Found in app/models/combination.rb - About 3 hrs to fix

      Method full_name_hash has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def full_name_hash
          gender = nil
          data = {}
          protonyms_by_rank.each do |rank, i|
            gender = i.gender_name if rank == 'genus'
      Severity: Minor
      Found in app/models/combination.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

      Consider simplifying this complex logical expression.
      Open

          if data['species'].nil? && (!data['subspecies'].nil? || !data['variety'].nil? || !data['subvariety'].nil? || !data['form'].nil? || !data['subform'].nil?)
            data['species'] = [nil, "[SPECIES NOT SPECIFIED]"]
          end
      Severity: Major
      Found in app/models/combination.rb - About 40 mins to fix

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

          def composition
            c = protonyms.count
        
            if c == 0
              errors.add(:base, 'Combination includes no names.')
        Severity: Minor
        Found in app/models/combination.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 dynamic find_by_protonym_ids.
        Open

              a = find_by_protonym_ids(**keyword_args).first
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks dynamic find_by_* methods. Use find_by instead of dynamic method. See. https://github.com/rubocop-hq/rails-style-guide#find_by

        Example:

        # bad
        User.find_by_name(name)
        
        # bad
        User.find_by_name_and_email(name)
        
        # bad
        User.find_by_email!(name)
        
        # good
        User.find_by(name: name)
        
        # good
        User.find_by(name: name, email: email)
        
        # good
        User.find_by!(email: email)

        Use find_by instead of dynamic find_by_protonym_ids.
        Open

              a = find_by_protonym_ids(**keyword_args).where(cached: name).first
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks dynamic find_by_* methods. Use find_by instead of dynamic method. See. https://github.com/rubocop-hq/rails-style-guide#find_by

        Example:

        # bad
        User.find_by_name(name)
        
        # bad
        User.find_by_name_and_email(name)
        
        # bad
        User.find_by_email!(name)
        
        # good
        User.find_by(name: name)
        
        # good
        User.find_by(name: name, email: email)
        
        # good
        User.find_by!(email: email)

        Specify an :inverse_of option.
        Open

          has_many :combination_relationships, -> {
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Specify an :inverse_of option.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :subject_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Specify an :inverse_of option.
        Open

                has_many relationships, -> {
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Specify an :inverse_of option.
        Open

            has_one "#{rank}_taxon_name_relationship".to_sym, -> {
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Specify a :dependent option.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :subject_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

        Example:

        # bad
        class User < ActiveRecord::Base
          has_many :comments
          has_one :avatar
        end
        
        # good
        class User < ActiveRecord::Base
          has_many :comments, dependent: :restrict_with_exception
          has_one :avatar, dependent: :destroy
          has_many :patients, through: :appointments
        end

        Prefer self[:attr] = val over write_attribute(:attr, val).
        Open

            write_attribute(:parent_id, names.first.parent.id) if names.count > 0 && names.first.parent
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks for the use of the read_attribute or write_attribute methods and recommends square brackets instead.

        If an attribute is missing from the instance (for example, when initialized by a partial select) then read_attribute will return nil, but square brackets will raise an ActiveModel::MissingAttributeError.

        Explicitly raising an error in this situation is preferable, and that is why rubocop recommends using square brackets.

        Example:

        # bad
        x = read_attribute(:attr)
        write_attribute(:attr, val)
        
        # good
        x = self[:attr]
        self[:attr] = val

        Specify a :dependent option.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :object_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

        Example:

        # bad
        class User < ActiveRecord::Base
          has_many :comments
          has_one :avatar
        end
        
        # good
        class User < ActiveRecord::Base
          has_many :comments, dependent: :restrict_with_exception
          has_one :avatar, dependent: :destroy
          has_many :patients, through: :appointments
        end

        Use find_by instead of where.first.
        Open

              a = find_by_protonym_ids(**keyword_args).where(cached: name).first
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        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')

        Specify an :inverse_of option.
        Open

                has_many relationships, -> {
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Use ay.presence instead of ay.blank? ? nil : ay.
        Open

            ay.blank? ? nil : ay
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks code that can be written more easily using Object#presence defined by Active Support.

        Example:

        # bad
        a.present? ? a : nil
        
        # bad
        !a.present? ? nil : a
        
        # bad
        a.blank? ? nil : a
        
        # bad
        !a.blank? ? a : nil
        
        # good
        a.presence

        Example:

        # bad
        a.present? ? a : b
        
        # bad
        !a.present? ? b : a
        
        # bad
        a.blank? ? b : a
        
        # bad
        !a.blank? ? a : b
        
        # good
        a.presence || b

        Specify an :inverse_of option.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :object_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where Active Record can't automatically determine the inverse association because of a scope or the options used. Using the blog with order scope example below, traversing the a Blog's association in both directions with blog.posts.first.blog would cause the blog to be loaded from the database twice.

        :inverse_of must be manually specified for Active Record to use the associated object in memory, or set to false to opt-out. Note that setting nil does not stop Active Record from trying to determine the inverse automatically, and is not considered a valid value for this.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: :blog)
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        # When you don't want to use the inverse association.
        class Blog < ApplicationRecord
          has_many(:posts,
                   -> { order(published_at: :desc) },
                   inverse_of: false)
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Use a string value for class_name.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :subject_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks if the value of the option class_name, in the definition of a reflection is a string.

        Example:

        # bad
        has_many :accounts, class_name: Account
        has_many :accounts, class_name: Account.name
        
        # good
        has_many :accounts, class_name: 'Account'

        Use value.present? instead of !value.blank?.
        Open

              if !value.blank?
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

        Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

        Example: NotNilAndNotEmpty: true (default)

        # Converts usages of `!nil? && !empty?` to `present?`
        
        # bad
        !foo.nil? && !foo.empty?
        
        # bad
        foo != nil && !foo.empty?
        
        # good
        foo.present?

        Example: NotBlank: true (default)

        # Converts usages of `!blank?` to `present?`
        
        # bad
        !foo.blank?
        
        # bad
        not foo.blank?
        
        # good
        foo.present?

        Example: UnlessBlank: true (default)

        # Converts usages of `unless blank?` to `if present?`
        
        # bad
        something unless foo.blank?
        
        # good
        something if foo.present?

        Use a string value for class_name.
        Open

                has_one relationship, class_name: d.name.to_s, foreign_key: :object_taxon_name_id
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        This cop checks if the value of the option class_name, in the definition of a reflection is a string.

        Example:

        # bad
        has_many :accounts, class_name: Account
        has_many :accounts, class_name: Account.name
        
        # good
        has_many :accounts, class_name: 'Account'

        TODO found
        Open

          # TODO: make access private
        Severity: Minor
        Found in app/models/combination.rb by fixme

        TODO found
        Open

          # The ranks that can be used to build combinations. ! TODO:  family group names 
        Severity: Minor
        Found in app/models/combination.rb by fixme

        TODO found
        Open

          # TODO: this is a TaxonName level validation, it doesn't belong here
        Severity: Minor
        Found in app/models/combination.rb by fixme

        TODO found
        Open

          # TODO: DEPRECATE this is likely not required in our new interfaces
        Severity: Minor
        Found in app/models/combination.rb by fixme

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

          TaxonNameRelationship.descendants.each do |d|
            if d.respond_to?(:assignment_method)
              if d.name.to_s =~ /TaxonNameRelationship::SourceClassifiedAs/
                relationship = "#{d.assignment_method}_relationship".to_sym
                has_one relationship, class_name: d.name.to_s, foreign_key: :subject_taxon_name_id
        Severity: Major
        Found in app/models/combination.rb and 1 other location - About 4 hrs to fix
        app/models/protonym.rb on lines 67..99

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

        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

            if data['species'].nil? && (!data['subspecies'].nil? || !data['variety'].nil? || !data['subvariety'].nil? || !data['form'].nil? || !data['subform'].nil?)
              data['species'] = [nil, "[SPECIES NOT SPECIFIED]"]
            end
        Severity: Minor
        Found in app/models/combination.rb and 1 other location - About 45 mins to fix
        app/models/taxon_name.rb on lines 961..963

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

        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

              if ['genus', 'subgenus', 'species', 'subspecies'].include? (rank)
                data[rank] = [nil, i.name_with_misspelling(gender)]
              else
                data[rank] = [i.rank_class.abbreviation, i.name_with_misspelling(gender)]
        Severity: Minor
        Found in app/models/combination.rb and 1 other location - About 15 mins to fix
        app/models/taxon_name.rb on lines 943..946

        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

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

              data['variety'] = [nil, "[VARIETY NOT SPECIFIED]"]
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

              data['genus'] = [nil, "[GENUS NOT SPECIFIED]"]
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

              data['species'] = [nil, "[SPECIES NOT SPECIFIED]"]
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

              data['form'] = [nil, "[FORM NOT SPECIFIED]"]
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

            b = b.as("z_bar")
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

            a = c.alias("a_foo")
        Severity: Minor
        Found in app/models/combination.rb by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        There are no issues that match your filters.

        Category
        Status