ucsdlib/damspas

View on GitHub
app/models/datastreams/dams_resource_datastream.rb

Summary

Maintainability
F
1 wk
Test Coverage

File dams_resource_datastream.rb has 690 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'timeout'

class DamsResourceDatastream < ActiveFedora::RdfxmlRDFDatastream
  include Dams::DamsHelper
  rdf_subject { |ds|
Severity: Major
Found in app/models/datastreams/dams_resource_datastream.rb - About 1 day to fix

    Class DamsResourceDatastream has 79 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class DamsResourceDatastream < ActiveFedora::RdfxmlRDFDatastream
      include Dams::DamsHelper
      rdf_subject { |ds|
        if ds.pid.nil?
          RDF::URI.new
    Severity: Major
    Found in app/models/datastreams/dams_resource_datastream.rb - About 1 day to fix

      Method events_to_json has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

        def events_to_json( event )
          event_array = []
          events = load_events event
          if events != nil
            n = 0
      Severity: Minor
      Found in app/models/datastreams/dams_resource_datastream.rb - About 6 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 insertTitleFields has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

        def insertTitleFields ( solr_doc, cid, titles )
          sort_title = ""
          titles.each do |t|
            begin
              if(t.name.class == ActiveFedora::RdfNode::TermProxy)
      Severity: Minor
      Found in app/models/datastreams/dams_resource_datastream.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 insertDateFields has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def insertDateFields (solr_doc, cid, dates)
          date_begin = nil
          date_end = nil
          date_val = nil
      
      
      Severity: Minor
      Found in app/models/datastreams/dams_resource_datastream.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 insertTitleFields has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def insertTitleFields ( solr_doc, cid, titles )
          sort_title = ""
          titles.each do |t|
            begin
              if(t.name.class == ActiveFedora::RdfNode::TermProxy)
      Severity: Major
      Found in app/models/datastreams/dams_resource_datastream.rb - About 2 hrs to fix

        Method to_solr has 66 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def to_solr (solr_doc = {})
            super(solr_doc)
        
            facetable = Solrizer::Descriptor.new(:string, :indexed, :multivalued)
        
        
        Severity: Major
        Found in app/models/datastreams/dams_resource_datastream.rb - About 2 hrs to fix

          Method insertRelationshipFields has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

            def insertRelationshipFields ( solr_doc, prefix, relationships )
          
              facetable = Solrizer::Descriptor.new(:string, :indexed, :multivalued)
              # build map: role => [name1,name2]
              rels = {}
          Severity: Minor
          Found in app/models/datastreams/dams_resource_datastream.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 events_to_json has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def events_to_json( event )
              event_array = []
              events = load_events event
              if events != nil
                n = 0
          Severity: Major
          Found in app/models/datastreams/dams_resource_datastream.rb - About 2 hrs to fix

            Method insertDateFields has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def insertDateFields (solr_doc, cid, dates)
                date_begin = nil
                date_end = nil
                date_val = nil
            
            
            Severity: Minor
            Found in app/models/datastreams/dams_resource_datastream.rb - About 2 hrs to fix

              Method insertRelationshipFields has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def insertRelationshipFields ( solr_doc, prefix, relationships )
              
                  facetable = Solrizer::Descriptor.new(:string, :indexed, :multivalued)
                  # build map: role => [name1,name2]
                  rels = {}
              Severity: Minor
              Found in app/models/datastreams/dams_resource_datastream.rb - About 1 hr to fix

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

                  def clean_date( date )
                    d = date || ''
                    return '' unless d.match( '^\d{4}' )
                
                    # pad yyyy or yyyy-mm dates out to yyyy-mm-dd
                Severity: Minor
                Found in app/models/datastreams/dams_resource_datastream.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 insertLanguageFields has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def insertLanguageFields ( solr_doc, field, languages )
                    langs = load_languages languages
                    if langs != nil
                      n = 0
                      langs.map.each do |lang|
                Severity: Minor
                Found in app/models/datastreams/dams_resource_datastream.rb - About 1 hr to fix

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

                    def insertLanguageFields ( solr_doc, field, languages )
                      langs = load_languages languages
                      if langs != nil
                        n = 0
                        langs.map.each do |lang|
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.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 insertCollectionFields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def insertCollectionFields (solr_doc, fieldName, objects, className)
                        i = 0
                      objects.map do |part|
                        part_json = {}
                        part_obj = nil
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.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 to_solr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def to_solr (solr_doc = {})
                      super(solr_doc)
                  
                      facetable = Solrizer::Descriptor.new(:string, :indexed, :multivalued)
                  
                  
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.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 find_children has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def find_children(p)
                      kids = @parents[p]
                      if kids != nil && kids.length > 0
                  
                        # replace children with nested hashes recursively
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.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 load_events has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def load_events(event)
                      events = []
                      event.each do |e|
                        begin
                            if !e.outcome.first.nil? && e.outcome.first != ""
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.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

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

                          date_json = {
                            :beginDate=>date.beginDate.first.to_s,
                            :endDate=>date.endDate.first.to_s,
                            :value=>date.value.first.to_s,
                            :type=>date.type.first.to_s,
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.rb and 1 other location - About 20 mins to fix
                  app/models/datastreams/dams_resource_datastream.rb on lines 342..342

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

                  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

                          date_json = {:beginDate=>date.beginDate.first.to_s, :endDate=>date.endDate.first.to_s, :value=>date.value.first.to_s, :type=>date.type.first.to_s, :encoding=>date.encoding.first.to_s }
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.rb and 1 other location - About 20 mins to fix
                  app/models/datastreams/dams_resource_datastream.rb on lines 345..350

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

                  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

                              if !relationship.name.first.nil? && !relationship.name.first.pid.nil? && (relationship.name.first.pid.include? 'dams:')
                                  rel_json[:name] = relationship.name.first.pid        
                              end         
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.rb and 1 other location - About 20 mins to fix
                  app/models/datastreams/dams_resource_datastream.rb on lines 687..689

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

                  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

                                if !relationship.role.first.nil? && !relationship.role.first.pid.nil? && (relationship.role.first.pid.include? 'dams:')
                                  rel_json[:role] = relationship.role.first.pid        
                                end               
                  Severity: Minor
                  Found in app/models/datastreams/dams_resource_datastream.rb and 1 other location - About 20 mins to fix
                  app/models/datastreams/dams_resource_datastream.rb on lines 667..669

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

                  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