riboseinc/relaton

View on GitHub
lib/relaton/db.rb

Summary

Maintainability
D
2 days
Test Coverage

Method check_bibliocache has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
      id, searchcode = std_id(code, year, opts, stdclass)
      yaml = @static_db[id]
      if yaml
        return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml)
Severity: Minor
Found in lib/relaton/db.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

Class Db has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Db
    # @param global_cache [String] directory of global DB
    # @param local_cache [String] directory of local DB
    def initialize(global_cache, local_cache)
      @registry = Relaton::Registry.instance
Severity: Minor
Found in lib/relaton/db.rb - About 3 hrs to fix

    File db.rb has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "yaml"
    require_relative "registry"
    require_relative "db_cache"
    
    module Relaton
    Severity: Minor
    Found in lib/relaton/db.rb - About 2 hrs to fix

      Method check_bibliocache has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
            id, searchcode = std_id(code, year, opts, stdclass)
            yaml = @static_db[id]
            if yaml
              return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml)
      Severity: Minor
      Found in lib/relaton/db.rb - About 1 hr to fix

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

            def fetch_async(code, year = nil, opts = {}, &block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
              stdclass = standard_class code
              if stdclass
                unless @queues[stdclass]
                  processor = @registry.processors[stdclass]
        Severity: Minor
        Found in lib/relaton/db.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 combine_doc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
              if (refs = code.split " + ").size > 1
                reltype = "derivedFrom"
                reldesc = nil
              elsif (refs = code.split ", ").size > 1
        Severity: Minor
        Found in lib/relaton/db.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 search_xml has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def search_xml(file, xml, text, edition, year)
        Severity: Minor
        Found in lib/relaton/db.rb - About 35 mins to fix

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

              def search_yml(file, yml, text, edition, year)
          Severity: Minor
          Found in lib/relaton/db.rb - About 35 mins to fix

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

                def net_retry(code, year, opts, stdclass, retries)
            Severity: Minor
            Found in lib/relaton/db.rb - About 35 mins to fix

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

                  def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
              Severity: Minor
              Found in lib/relaton/db.rb - About 35 mins to fix

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

                    def open_cache_biblio(dir, type: :static) # rubocop:disable Metrics/MethodLength
                      return nil if dir.nil?
                
                      db = DbCache.new dir, type == :static ? "yml" : "xml"
                      return db if type == :static
                Severity: Minor
                Found in lib/relaton/db.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 search_edition_year has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
                      processor = @registry.processors[standard_class(file.split("/")[-2])]
                      item = if file.match?(/xml$/) then processor.from_xml(content)
                             else processor.hash_to_bib(YAML.safe_load(content))
                             end
                Severity: Minor
                Found in lib/relaton/db.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

                Avoid too many return statements within this method.
                Open

                        return bib_retval(db[id], stdclass) if opts[:fetch_db]
                Severity: Major
                Found in lib/relaton/db.rb - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status