datacite/poodle

View on GitHub

Showing 12 of 22 total issues

Method extract_url has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def extract_url(doi: nil, data: nil)
      hsh = data.split("\n").map do |line| 
        arr = line.to_s.split("=", 2)
        arr << "value" if arr.length < 2
        arr
Severity: Minor
Found in app/controllers/concerns/doiable.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 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 update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    if (safe_params[:id].present? || safe_params[:doi].present?) && safe_params[:url].present?
      doi = safe_params[:id] || safe_params[:doi]
      url = safe_params[:url]
    elsif safe_params[:data].present?
Severity: Minor
Found in app/controllers/dois_controller.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 has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    if request.content_type == "application/x-www-form-urlencoded"
      render plain: "Content type application/x-www-form-urlencoded is not supported", status: :unsupported_media_type
      return
    end
Severity: Minor
Found in app/controllers/metadata_controller.rb - About 1 hr to fix

    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 create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          if request.content_type == "application/x-www-form-urlencoded"
            render plain: "Content type application/x-www-form-urlencoded is not supported", status: :unsupported_media_type
            return
          end
      Severity: Minor
      Found in app/controllers/metadata_controller.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 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

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

        def index
          @doi = validate_doi(params[:doi_id])
          fail AbstractController::ActionNotFound unless @doi.present?
      
          response = MetadataController.get_metadata(@doi, username: username, password: password)
      Severity: Minor
      Found in app/controllers/metadata_controller.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 index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          response = MediaController.list_media(@doi, username: username, password: password)
      
          if response.status == 200 && response.body["data"].present?
            render plain: response.body["data"], status: :ok
      Severity: Minor
      Found in app/controllers/media_controller.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 show has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def show
          response = DoisController.get_doi(@doi, username: username, password: password)
      
          if response.status == 200
            render plain: response.body.dig("data", "url"), status: :ok
      Severity: Minor
      Found in app/controllers/dois_controller.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

      Severity
      Category
      Status
      Source
      Language