archivesspace/archivesspace

View on GitHub
backend/app/lib/oai/mappers/oai_dc.rb

Summary

Maintainability
F
3 days
Test Coverage

Method map_oai_record has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring.
Open

  def map_oai_record(record)
    jsonmodel = record.jsonmodel_record
    result = Nokogiri::XML::Builder.new do |xml|
      xml['oai_dc'].dc('xmlns:oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/',
                       'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
Severity: Minor
Found in backend/app/lib/oai/mappers/oai_dc.rb - About 1 day 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 map_oai_record has 134 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def map_oai_record(record)
    jsonmodel = record.jsonmodel_record
    result = Nokogiri::XML::Builder.new do |xml|
      xml['oai_dc'].dc('xmlns:oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/',
                       'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
Severity: Major
Found in backend/app/lib/oai/mappers/oai_dc.rb - About 5 hrs to fix

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

            if (lang_materials = Array(jsonmodel['lang_materials']))
              language_vals = lang_materials.map {|l| l['language_and_script']}.compact
              if !language_vals.empty?
                language_vals.each do |l|
                  xml['dc'].language(l['language'])
    Severity: Major
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 2 hrs to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 113..127

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

    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

            Array(jsonmodel['subjects']).each do |subject|
              term_types = subject['_resolved']['terms'].map {|term| term['term_type']}
    
              if term_types.include?('geographic')
                xml['dc'].coverage(subject['_resolved']['title'])
    Severity: Major
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 1 hr to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 188..197

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

    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 jsonmodel['jsonmodel_type'] == 'archival_object'
              resource_id_str = (0..3).map {|i| jsonmodel['resource']['_resolved']["id_#{i}"]}.compact.join(".")
              resource_str = [jsonmodel['resource']['_resolved']['title'], resource_id_str].join(', ')
    
              xml['dc'].relation(resource_str)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 45 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 219..223

    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

            merged_identifier = if jsonmodel['jsonmodel_type'] == 'archival_object'
                                  ([jsonmodel['component_id']] + jsonmodel['ancestors'].map {|a| a['_resolved']['component_id']}).compact.reverse.uniq.join(".")
                                else
                                  (0..3).map {|id| jsonmodel["id_#{id}"]}.compact.join('.')
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 45 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 23..26

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

    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

            Array(jsonmodel['extents']).each do |extent|
              extent_str = [extent['number'] + ' ' + I18n.t('enumerations.extent_extent_type.' + extent['extent_type'], :default => extent['extent_type']), extent['container_summary']].compact.join('; ')
              xml['dc'].format(extent_str)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 45 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 98..100

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

    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

            Array(jsonmodel['linked_agents']).each do |link|
              next unless link['_resolved']['publish']
    
              if link['role'] == 'creator' && !['ctb' , 'pbl'].include?(link['relator'])
                xml['dc'].creator(link['_resolved']['title'])
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 45 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 45..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 39.

    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 4 locations. Consider refactoring.
    Open

            Array(jsonmodel['linked_agents']).each do |link|
              next unless link['_resolved']['publish']
    
              if link['role'] == 'creator' && ['pbl'].include?(link['relator'])
                xml['dc'].publisher(link['_resolved']['title'])
    Severity: Major
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 3 other locations - About 40 mins to fix
    backend/app/lib/oai/mappers/oai_dc.rb on lines 53..58
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 54..59
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 63..68

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

    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 4 locations. Consider refactoring.
    Open

            Array(jsonmodel['linked_agents']).each do |link|
              next unless link['_resolved']['publish']
    
              if link['role'] == 'creator' && ['ctb'].include?(link['relator'])
                xml['dc'].contributor(link['_resolved']['title'])
    Severity: Major
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 3 other locations - About 40 mins to fix
    backend/app/lib/oai/mappers/oai_dc.rb on lines 62..67
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 54..59
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 63..68

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

    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

            Array(jsonmodel['notes'])
              .select {|note| ['originalsloc', 'altformavail', 'separatedmaterial', 'relatedmaterial'].include?(note['type'])}
              .each do |note|
              OAIUtils.extract_published_note_content(note).each do |content|
                xml['dc'].relation(content)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 25 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 152..156

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

    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

            Array(jsonmodel['linked_agents']).each do |link|
              next unless link['_resolved']['publish']
    
              if link['role'] == 'subject'
                xml['dc'].subject(link['_resolved']['title'])
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 1 other location - About 25 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 201..205

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

    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 4 locations. Consider refactoring.
    Open

            Array(jsonmodel['notes'])
              .select {|note| ['physdesc', 'dimensions'].include?(note['type'])}
              .each do |note|
              OAIUtils.extract_published_note_content(note).each do |content|
                xml['dc'].format(content)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 3 other locations - About 20 mins to fix
    backend/app/lib/oai/mappers/oai_dc.rb on lines 138..142
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 104..108
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 161..165

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

    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 4 locations. Consider refactoring.
    Open

            Array(jsonmodel['notes'])
              .select {|note| ['accessrestrict', 'userestrict'].include?(note['type'])}
              .each do |note|
              OAIUtils.extract_published_note_content(note).each do |content|
                xml['dc'].rights(content)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 3 other locations - About 20 mins to fix
    backend/app/lib/oai/mappers/oai_dc.rb on lines 90..94
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 104..108
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 161..165

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

    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 5 locations. Consider refactoring.
    Open

            Array(jsonmodel['notes'])
              .select {|note| ['physfacet'].include?(note['type'])}
              .each do |note|
              OAIUtils.extract_published_note_content(note).each do |content|
                xml['dc'].type(content)
    Severity: Minor
    Found in backend/app/lib/oai/mappers/oai_dc.rb and 4 other locations - About 20 mins to fix
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 143..147
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 170..174
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 179..183
    backend/app/lib/oai/mappers/oai_dcterms.rb on lines 210..214

    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