archivesspace/archivesspace

View on GitHub
backend/app/exporters/serializers/marc_auth.rb

Summary

Maintainability
F
4 days
Test Coverage

File marc_auth.rb has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class MARCAuthSerializer < ASpaceExport::Serializer
  serializer_for :marc_auth

  def serialize(marc, _opts = {})
    builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
Severity: Major
Found in backend/app/exporters/serializers/marc_auth.rb - About 1 day to fix

    Method controlfield_008 has 128 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def controlfield_008(json, xml)
        created_maint_events = json['agent_maintenance_histories'].select { |amh| amh['maintenance_event_type'] == 'created' }
        pos0_5 = if created_maint_events.any?
                   created_maint_events.first['event_date'].strftime('%y%m%d')
                 else
    Severity: Major
    Found in backend/app/exporters/serializers/marc_auth.rb - About 5 hrs to fix

      Class MARCAuthSerializer has 37 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class MARCAuthSerializer < ASpaceExport::Serializer
        serializer_for :marc_auth
      
        def serialize(marc, _opts = {})
          builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
      Severity: Minor
      Found in backend/app/exporters/serializers/marc_auth.rb - About 4 hrs to fix

        Method controlfield_008 has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

          def controlfield_008(json, xml)
            created_maint_events = json['agent_maintenance_histories'].select { |amh| amh['maintenance_event_type'] == 'created' }
            pos0_5 = if created_maint_events.any?
                       created_maint_events.first['event_date'].strftime('%y%m%d')
                     else
        Severity: Minor
        Found in backend/app/exporters/serializers/marc_auth.rb - About 3 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 notes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          def notes(json, xml)
            with_value(json['notes'], 'jsonmodel_type', 'note_bioghist') do |note|
              ind1 = agent_type(json) == :person || agent_type(json) == :family_name ? '0' : '1'
              xml.datafield(tag: '678', ind1: ind1, ind2: ' ') do
                with_value(note['subnotes'], 'jsonmodel_type', 'note_abstract') do |abstract|
        Severity: Minor
        Found in backend/app/exporters/serializers/marc_auth.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 _leader has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def _leader(json, xml)
            xml.leader do
              if json['agent_record_controls']&.any?
                arc = json['agent_record_controls'].first
        
        
        Severity: Minor
        Found in backend/app/exporters/serializers/marc_auth.rb - About 1 hr to fix

          Method relationships has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def relationships(json, xml)
              json['related_agents'].each do |ra|
                agent = ra['_resolved']
                primary = agent['names'].select { |n| n['authorized'] == true }.first
                # smuggle in the relator info. for this relationship
          Severity: Minor
          Found in backend/app/exporters/serializers/marc_auth.rb - About 1 hr to fix

            Method _marc has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def _marc(obj, xml)
                json = obj.json
                xml.collection(
                  'xmlns' => 'https://www.loc.gov/MARC21/slim',
                  'xmlns:marc' => 'https://www.loc.gov/MARC21/slim',
            Severity: Minor
            Found in backend/app/exporters/serializers/marc_auth.rb - About 1 hr to fix

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

                def _leader(json, xml)
                  xml.leader do
                    if json['agent_record_controls']&.any?
                      arc = json['agent_record_controls'].first
              
              
              Severity: Minor
              Found in backend/app/exporters/serializers/marc_auth.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 relationships has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def relationships(json, xml)
                  json['related_agents'].each do |ra|
                    agent = ra['_resolved']
                    primary = agent['names'].select { |n| n['authorized'] == true }.first
                    # smuggle in the relator info. for this relationship
              Severity: Minor
              Found in backend/app/exporters/serializers/marc_auth.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 record_ids has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def record_ids(json, xml)
                  return unless json['agent_record_identifiers']&.any?
              
                  identifiers = json['agent_record_identifiers']
                  props = ['identifier_type']
              Severity: Minor
              Found in backend/app/exporters/serializers/marc_auth.rb - About 1 hr to fix

                Method names_person has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def names_person(primary, not_primary, parallel, xml)
                    # the primary name gets the 100 tag
                    if primary
                      ind1 = primary['name_order'] == 'indirect' ? '1' : '0'
                      xml.datafield(tag: '100', ind1: ind1, ind2: ' ') do
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb - About 35 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

                Method name_formatter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def name_formatter(parts, xml, omit_first_sub_prefix: false)
                    primary_subfield = parts.shift
                    subf(primary_subfield[:code], primary_subfield[:value], xml)
                
                    return unless parts.any? # jump ship if we don't have more parts
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb - About 35 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

                Method names_corporate_entity has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def names_corporate_entity(primary, not_primary, parallel, xml)
                    if primary
                      if primary['conference_meeting'] == true
                        xml.datafield(tag: '111', ind1: '2', ind2: ' ') do
                          corporate_name_subtags(primary, xml)
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb - About 35 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

                Method family_name_subtags has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  def family_name_subtags(name, xml, related = false)
                    related_sfs(name, xml) if related
                
                    name_parts = [
                      { code: 'c', value: name['location'] },
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb - About 25 mins to fix

                Cognitive Complexity

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

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

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

                Further reading

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

                      if n['conference_meeting'] == true
                        xml.datafield(tag: '411', ind1: '2', ind2: ' ') do
                          corporate_name_subtags(n, xml)
                        end
                      else
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 30 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 423..429

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

                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 primary['conference_meeting'] == true
                        xml.datafield(tag: '111', ind1: '2', ind2: ' ') do
                          corporate_name_subtags(primary, xml)
                        end
                      else
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 30 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 436..442

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

                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

                    with_value(identifiers, props, 'local') do |record|
                      xml.datafield(tag: '035', ind1: ' ', ind2: ' ') do
                        subf('a', record['record_identifier'], xml)
                        subf('2', record['source'], xml)
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 25 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 265..268

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

                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

                      case arc['cataloging_source']
                      when 'nat_bib_agency'
                        pos_39 = ' '
                      when 'ccp'
                        pos_39 = 'c'
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 25 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 524..534

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

                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

                    with_value(identifiers, props, 'lac') do |record|
                      xml.datafield(tag: '016', ind1: '7', ind2: ' ') do
                        subf('a', record['record_identifier'], xml)
                        subf('2', record['source'], xml)
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 25 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 279..282

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

                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

                      case place['place_role']
                      when 'place_of_birth'
                        subfield_code = 'a'
                      when 'place_of_death'
                        subfield_code = 'b'
                Severity: Minor
                Found in backend/app/exporters/serializers/marc_auth.rb and 1 other location - About 25 mins to fix
                backend/app/exporters/serializers/marc_auth.rb on lines 224..234

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

                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