duke-libraries/ddr-models

View on GitHub

Showing 35 of 35 total issues

Method index_fields has 120 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def index_fields
      fields = {
        ACCESS_ROLE             => roles.to_json,
        ADMIN_SET               => admin_set,
        ADMIN_SET_TITLE         => admin_set_title,
Severity: Major
Found in lib/ddr/models/indexing.rb - About 4 hrs to fix

    Class PermanentId has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class PermanentId
    
        class Error < Ddr::Models::Error; end
        class AssignmentFailed < Error; end
        class RepoObjectNotPersisted < Error; end
    Severity: Minor
    Found in lib/ddr/models/permanent_id.rb - About 3 hrs to fix

      Class Structure has 29 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Structure < SimpleDelegator
      
          # Indicates whether the structure is externally provided or maintained by the repository itself (i.e., is the
          # default structure for the object).
          EXTERNALLY_PROVIDED = 'provided'.freeze
      Severity: Minor
      Found in lib/ddr/models/structure.rb - About 3 hrs to fix

        Class Base has 29 methods (exceeds 20 allowed). Consider refactoring.
        Open

            class Base < ActiveFedora::Base
              extend Deprecation
        
              self.deprecation_horizon = 'ddr-models v3.0'
        
        
        Severity: Minor
        Found in lib/ddr/models/base.rb - About 3 hrs to fix

          File solr_document.rb has 310 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'json'
          
          module Ddr::Models
            module SolrDocument
              extend ActiveSupport::Concern
          Severity: Minor
          Found in lib/ddr/models/solr_document.rb - About 3 hrs to fix

            Class Event has 22 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class Event < ActiveRecord::Base
            
                  # ActiveSupport::Notifications::Instrumenter sets payload[:exception]
                  #   to an array of [<exception class name>, <exception message>]
                  #   and we want to store this data in a string field.
            Severity: Minor
            Found in lib/ddr/events/event.rb - About 2 hrs to fix

              Method index_fields has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

                  def index_fields
                    fields = {
                      ACCESS_ROLE             => roles.to_json,
                      ADMIN_SET               => admin_set,
                      ADMIN_SET_TITLE         => admin_set_title,
              Severity: Minor
              Found in lib/ddr/models/indexing.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 update_derivatives has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update_derivatives(schedule=SCHEDULE_LATER)
                    raise ArgumentError, "Must be one of #{SCHEDULES}" unless SCHEDULES.include?(schedule)
                    Ddr::Derivatives::DERIVATIVES.values.each do |derivative|
                      if Ddr::Derivatives.update_derivatives.include?(derivative.name)
                        # Need to update derivative if object has a datastream for this type of derivative and
              Severity: Minor
              Found in lib/ddr/managers/derivatives_manager.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

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

                  def self.build(args)
                    node = Nokogiri::XML::Node.new('div', args[:document])
                    node['ID'] = args[:id] if args[:id]
                    node['LABEL'] = args[:label] if args[:label]
                    node['ORDER'] = args[:order] if args[:order]
              Severity: Major
              Found in lib/ddr/models/structures/div.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/structures/f_locat.rb on lines 43..50

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 63.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                  def self.build(args)
                    node = Nokogiri::XML::Node.new('FLocat', args[:document])
                    node['ID'] = args[:id] if args[:id]
                    node['LOCTYPE'] = args[:loctype] if args[:loctype]
                    node['OTHERLOCTYPE'] = args[:otherloctype] if args[:otherloctype]
              Severity: Major
              Found in lib/ddr/models/structures/f_locat.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/structures/div.rb on lines 53..60

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 63.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                module Captionable
                  extend ActiveSupport::Concern
              
                  included do
                    has_file_datastream name: Ddr::Datastreams::CAPTION,
              Severity: Major
              Found in lib/ddr/models/captionable.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/streamable.rb on lines 2..33

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

              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

                module Streamable
                  extend ActiveSupport::Concern
              
                  included do
                    has_file_datastream name: Ddr::Datastreams::STREAMABLE_MEDIA,
              Severity: Major
              Found in lib/ddr/models/streamable.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/captionable.rb on lines 2..33

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

              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

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

                def self.pid_for_identifier(identifier, opts={})
                  model = opts.fetch(:model, nil)
                  collection = opts.fetch(:collection, nil)
                  objs = []
                  ActiveFedora::Base.find_each( { Ddr::Index::Fields::IDENTIFIER_ALL => identifier }, { :cast => true } ) { |o| objs << o }
              Severity: Minor
              Found in lib/ddr/utils.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

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

                  def self.build(args)
                    node = Nokogiri::XML::Node.new('metsHdr', args[:document])
                    node['ID'] = args[:id] if args[:id]
                    node['CREATEDATE'] = args[:createdate] if args[:createdate]
                    node['LASTMODDATE'] = args[:lastmoddate] if args[:lastmoddate]
              Severity: Major
              Found in lib/ddr/models/structures/mets_hdr.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/structures/mptr.rb on lines 39..45

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

              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 self.build(args)
                    node = Nokogiri::XML::Node.new('mptr', args[:document])
                    node['ID'] = args[:id] if args[:id]
                    node['LOCTYPE'] = args[:loctype] if args[:loctype]
                    node['OTHERLOCTYPE'] = args[:otherloctype] if args[:otherloctype]
              Severity: Major
              Found in lib/ddr/models/structures/mptr.rb and 1 other location - About 1 hr to fix
              lib/ddr/models/structures/mets_hdr.rb on lines 27..33

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

              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

              Method validate_checksum! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                    def validate_checksum! checksum, checksum_type=nil
                      raise Ddr::Models::Error, "Checksum cannot be validated on new datastream." if new?
                      raise Ddr::Models::Error, "Checksum cannot be validated on unpersisted content." if content_changed?
                      raise Ddr::Models::ChecksumInvalid, "The repository internal checksum validation failed." unless dsChecksumValid
                      algorithm = checksum_type || self.checksumType
              Severity: Minor
              Found in lib/ddr/datastreams/datastream_behavior.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 call has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.call(file_or_path)
                    path = file_or_path.respond_to?(:path) ? file_or_path.path : file_or_path
                    # Use preferred media type, if available
                    media_type = Ddr::Models.preferred_media_types[(File.extname(path)).downcase]
                    if !media_type
              Severity: Minor
              Found in lib/ddr/models/media_type.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 desc_metadata_terms has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def desc_metadata_terms *args
                    return Ddr::Datastreams::DescriptiveMetadataDatastream.term_names if args.empty?
                    arg = args.pop
                    terms = case arg.to_sym
                            when :empty
              Severity: Minor
              Found in lib/ddr/models/describable.rb - About 1 hr to fix

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

                  def build_default_structure
                    document = Ddr::Models::Structure.xml_template
                    structure = Ddr::Models::Structure.new(document)
                    metshdr = structure.add_metshdr
                    structure.add_agent(parent: metshdr, role: Ddr::Models::Structures::Agent::ROLE_CREATOR,
                Severity: Minor
                Found in app/models/collection.rb and 1 other location - About 55 mins to fix
                app/models/item.rb on lines 46..54

                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

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

                  def build_default_structure
                    document = Ddr::Models::Structure.xml_template
                    structure = Ddr::Models::Structure.new(document)
                    metshdr = structure.add_metshdr
                    structure.add_agent(parent: metshdr, role: Ddr::Models::Structures::Agent::ROLE_CREATOR,
                Severity: Minor
                Found in app/models/item.rb and 1 other location - About 55 mins to fix
                app/models/collection.rb on lines 77..85

                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

                Severity
                Category
                Status
                Source
                Language