duke-libraries/ddr-models

View on GitHub

Showing 22 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

              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

              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

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

                    def self.call(*args)
                      event = ActiveSupport::Notifications::Event.new(*args)
                      repo_id, identifier_id, reason = event.payload.values_at(:pid, :permanent_id, :reason)
                      case event.name
                      when Base::UPDATE
                Severity: Minor
                Found in lib/ddr/models/permanent_id.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 generate_derivative! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def generate_derivative!(derivative)
                      tempdir_path = File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname('',nil))
                      begin
                        tempdir = FileUtils.mkdir(tempdir_path).first
                        generator_source_path = source_datastream.external? ? source_datastream.file_path
                Severity: Minor
                Found in lib/ddr/managers/derivatives_manager.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 desc_metadata_terms has a Cognitive Complexity of 9 (exceeds 5 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 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 dereferenced_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def dereferenced_hash
                      contents = []
                      contents.concat(divs.map { |div| div.dereferenced_hash }) unless divs.empty?
                      contents.concat(fptrs.map { |fptr| fptr.dereferenced_hash }) unless fptrs.empty?
                      contents.concat(mptrs.map { |mptr| mptr.dereferenced_hash }) unless mptrs.empty?
                Severity: Minor
                Found in lib/ddr/models/structures/div.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method method_missing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def method_missing(name, *args, &block)
                      if args.empty? && !block
                        begin
                          field = Ddr::Index::Fields.get(name)
                        rescue NameError
                Severity: Minor
                Found in lib/ddr/models/solr_document.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method user_groups has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                      def user_groups(user, raw = false)
                        groups = []
                        subject_id = user.principal_name.scan(SUBJECT_ID_RE).first
                        return groups unless subject_id
                        begin
                Severity: Minor
                Found in lib/ddr/auth/grouper_gateway.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method add_file has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def add_file(file, dsid, mime_type: nil, external: false, original_filename: nil)
                      mime_type         ||= MediaType.call(file) # XXX Should we use original_filename, if present?
                      source_path         = Ddr::Utils.file_path(file)
                      original_filename ||= Ddr::Utils.file_name(file)
                      file_to_add = FileToAdd.new(dsid, source_path, original_filename)
                Severity: Minor
                Found in lib/ddr/models/file_management.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method add_use_to_structure has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def add_use_to_structure(structure, filegrp, div, use, datastream_name)
                Severity: Minor
                Found in app/models/component.rb - About 35 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language