datacite/lupo

View on GitHub
app/models/concerns/helpable.rb

Summary

Maintainability
D
2 days
Test Coverage
F
17%

File helpable.rb has 298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Helpable
  extend ActiveSupport::Concern

  require "bolognese"
  require "csv"
Severity: Minor
Found in app/models/concerns/helpable.rb - About 3 hrs to fix

    Method register_url has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def register_url
          if url.blank?
            raise ActionController::BadRequest.new,
                  "[Handle] Error updating DOI " + doi + ": url missing."
          end
    Severity: Minor
    Found in app/models/concerns/helpable.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 register_url has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def register_url
          if url.blank?
            raise ActionController::BadRequest.new,
                  "[Handle] Error updating DOI " + doi + ": url missing."
          end
    Severity: Major
    Found in app/models/concerns/helpable.rb - About 2 hrs to fix

      Method get_dois has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def get_dois(options = {})
            if options[:prefix].blank?
              return OpenStruct.new(
                body: { "errors" => [{ "title" => "Prefix missing" }] },
              )
      Severity: Minor
      Found in app/models/concerns/helpable.rb - About 1 hr to fix

        Method get_doi has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_doi(options = {})
              if options[:doi].blank?
                return OpenStruct.new(
                  body: { "errors" => [{ "title" => "DOI missing" }] },
                )
        Severity: Minor
        Found in app/models/concerns/helpable.rb - About 1 hr to fix

          Method delete_doi has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def delete_doi(options = {})
                if options[:doi].blank?
                  return OpenStruct.new(
                    body: { "errors" => [{ "title" => "DOI missing" }] },
                  )
          Severity: Minor
          Found in app/models/concerns/helpable.rb - About 1 hr to fix

            Method parse_attributes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse_attributes(element, options = {})
                  content = options[:content] || "__content__"
            
                  if element.is_a?(String) && options[:content].nil?
                    CGI.unescapeHTML(element)
            Severity: Minor
            Found in app/models/concerns/helpable.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 get_dois has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_dois(options = {})
                  if options[:prefix].blank?
                    return OpenStruct.new(
                      body: { "errors" => [{ "title" => "Prefix missing" }] },
                    )
            Severity: Minor
            Found in app/models/concerns/helpable.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 encode_doi has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

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

                def match_url_with_domains(url: nil, domains: nil)
                  return false if url.blank? || domains.blank?
                  return true if domains == "*"
            
                  uri = Addressable::URI.parse(url)
            Severity: Minor
            Found in app/models/concerns/helpable.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 delete_doi has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def delete_doi(options = {})
                  if options[:doi].blank?
                    return OpenStruct.new(
                      body: { "errors" => [{ "title" => "DOI missing" }] },
                    )
            Severity: Minor
            Found in app/models/concerns/helpable.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 get_doi has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_doi(options = {})
                  if options[:doi].blank?
                    return OpenStruct.new(
                      body: { "errors" => [{ "title" => "DOI missing" }] },
                    )
            Severity: Minor
            Found in app/models/concerns/helpable.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 get_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_url
                  url = "#{ENV['HANDLE_URL']}/api/handles/#{doi}?index=1"
                  response = Maremma.get(url, ssl_self_signed: true, timeout: 10)
            
                  if response.status != 200
            Severity: Minor
            Found in app/models/concerns/helpable.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

            There are no issues that match your filters.

            Category
            Status