datacite/poodle

View on GitHub
app/controllers/concerns/metadatable.rb

Summary

Maintainability
B
4 hrs
Test Coverage
A
91%

Method find_from_format_by_string has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def find_from_format_by_string(string)
      if Maremma.from_xml(string).to_h.dig("doi_records", "doi_record", "crossref").present?
        "crossref"
      elsif Nokogiri::XML(string, nil, "UTF-8", &:noblanks).collect_namespaces.detect { |_, v| v.start_with?("http://datacite.org/schema/kernel") }
        "datacite"
Severity: Minor
Found in app/controllers/concerns/metadatable.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 generate_unique_doi has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def generate_unique_doi(str, options = {})
      if options[:number].present?
        doi = generate_random_doi(str, number: options[:number])
        fail IdentifierError, "doi:#{doi} has already been registered" if
          !MetadataController.get_metadata(doi, options).body.dig("errors")
Severity: Minor
Found in app/controllers/concerns/metadatable.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 create_metadata has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def create_metadata(doi, options = {})
      return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?

      xml = options[:data].present? ? ::Base64.strict_encode64(options[:data]) : nil

Severity: Minor
Found in app/controllers/concerns/metadatable.rb - About 1 hr to fix

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

        def encode_doi(prefix, options = {})
          prefix = validate_prefix(prefix)
          return nil if prefix.blank?
    
          number = options[:number].to_s.scan(/\d+/).join("").to_i
    Severity: Minor
    Found in app/controllers/concerns/metadatable.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 extract_doi has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def extract_doi(str, options = {})
          doi = validate_doi(str)
          return doi if doi.present?
    
          if options[:from] == "datacite"
    Severity: Minor
    Found in app/controllers/concerns/metadatable.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

    There are no issues that match your filters.

    Category
    Status