archivesspace/archivesspace

View on GitHub
backend/app/model/mixins/relationships.rb

Summary

Maintainability
F
4 days
Test Coverage

File relationships.rb has 569 lines of code (exceeds 250 allowed). Consider refactoring.
Open

AbstractRelationship = Class.new(Sequel::Model) do

  include ObjectGraph

  # Create a relationship instance between two objects with a defined set of properties.
Severity: Major
Found in backend/app/model/mixins/relationships.rb - About 1 day to fix

    Method transfer has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.transfer(target, victims)
        target_columns = self.reference_columns_for(target.class)
    
        victims_by_model = victims.reject {|v| (v.class == target.class) && (v.id == target.id)}.group_by(&:class)
    
    
    Severity: Minor
    Found in backend/app/model/mixins/relationships.rb - About 4 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 delete_existing_relationships has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def delete_existing_relationships(obj, bump_lock_version_on_referent = false, force = false, predicate = nil)
          relationships.each do |relationship_defn|
    
            next if (!relationship_defn.json_property && !force)
    
    
    Severity: Minor
    Found in backend/app/model/mixins/relationships.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 sequel_to_jsonmodel has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def sequel_to_jsonmodel(objs, opts = {})
          jsons = super
    
          return jsons if opts[:skip_relationships]
    
    
    Severity: Minor
    Found in backend/app/model/mixins/relationships.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 identify_duplicate_containers has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.identify_duplicate_containers(target, relationship, target_col, dups)
        find_by_participant(target).each do |target_relationship|
          subcontainer = SubContainer[relationship[:sub_container_id]]
          target_subcontainer = SubContainer[target_relationship[:sub_container_id]]
          # Only proceed if the subcontainer record is empty
    Severity: Minor
    Found in backend/app/model/mixins/relationships.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 transfer has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.transfer(target, victims)
        target_columns = self.reference_columns_for(target.class)
    
        victims_by_model = victims.reject {|v| (v.class == target.class) && (v.id == target.id)}.group_by(&:class)
    
    
    Severity: Minor
    Found in backend/app/model/mixins/relationships.rb - About 1 hr to fix

      Method relate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.relate(obj1, obj2, properties)
          columns = if obj1.class == obj2.class
            # If our two related objects are of the same type, we'll get back multiple
            # columns here anyway
                      raise ReferenceError.new("Can't relate an object to itself") if obj1.id == obj2.id
      Severity: Minor
      Found in backend/app/model/mixins/relationships.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 apply_relationships has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def apply_relationships(obj, json, opts, new_record = false)
            delete_existing_relationships(obj) if !new_record
      
            @relationships.each do |relationship_name, relationship_defn|
              property_name = relationship_defn.json_property
      Severity: Minor
      Found in backend/app/model/mixins/relationships.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 other_referent_than has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def other_referent_than(obj)
          self.class.participating_models.each {|model|
            self.class.reference_columns_for(model).each {|column|
              if self[column] && (model != obj.class || self[column] != obj.id)
                return model.respond_to?(:any_repo) ? model.any_repo[self[column]] : model[self[column]]
      Severity: Minor
      Found in backend/app/model/mixins/relationships.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 cleanup_container_profile_relationships has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.cleanup_container_profile_relationships(victim_container_profiles, target)
          target_relationship = nil
          find_by_participant(target).each do |target_rlshp|
            if !target_rlshp.nil? && target_rlshp.is_a?(Relationships::ContainerProfileTopContainerProfile)
              target_relationship = target_rlshp
      Severity: Minor
      Found in backend/app/model/mixins/relationships.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 transfer_to_repository has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def transfer_to_repository(repository, transfer_group = [])
          if transfer_group.empty?
            do_id = self.class == DigitalObject ? self[:id] : 0
          else
            do_id = transfer_group.first.class == DigitalObject ? transfer_group.first[:id] : 0
      Severity: Minor
      Found in backend/app/model/mixins/relationships.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 touch_mtime_of_anyone_related_to has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def touch_mtime_of_anyone_related_to(obj)
            now = Time.now
      
            relationships.map do |relationship_defn|
              models = relationship_defn.participating_models
      Severity: Minor
      Found in backend/app/model/mixins/relationships.rb - About 1 hr to fix

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

            def touch_mtime_of_anyone_related_to(obj)
              now = Time.now
        
              relationships.map do |relationship_defn|
                models = relationship_defn.participating_models
        Severity: Minor
        Found in backend/app/model/mixins/relationships.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 confirm_accepts_target has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.confirm_accepts_target(victim_model, vics)
            unless participating_models.include?(victim_model)
              found = self.find_by_participant_ids(victim_model, vics.map(&:id))
        
              unless found.empty?
        Severity: Minor
        Found in backend/app/model/mixins/relationships.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 define_relationship has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def define_relationship(opts)
              [:name, :contains_references_to_types].each do |p|
                opts[p] or raise "No #{p} given"
              end
        
        
        Severity: Minor
        Found in backend/app/model/mixins/relationships.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 uri_for_other_referent_than has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def uri_for_other_referent_than(obj)
            self.class.participating_models.each {|model|
              self.class.reference_columns_for(model).each {|column|
                if self[column] && (model != obj.class || self[column] != obj.id)
                  return model.my_jsonmodel.uri_for(self[column],
        Severity: Minor
        Found in backend/app/model/mixins/relationships.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

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

            ASModel.all_models.each do |model|
              next unless model.associations.include?(:instance)
        
              model
                .eager_graph(:instance)
        Severity: Minor
        Found in backend/app/model/mixins/relationships.rb and 1 other location - About 55 mins to fix
        backend/app/model/mixins/transferable.rb on lines 49..59

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

        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