datacite/levriero

View on GitHub
app/models/crossref.rb

Summary

Maintainability
B
5 hrs
Test Coverage
A
98%

Perceived complexity for queue_jobs is too high. [12/8]
Open

  def queue_jobs(options = {})
    options[:offset] = options[:offset].to_i || 0
    options[:rows] = options[:rows].presence || job_batch_size
    options[:from_date] =
      options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
Severity: Minor
Found in app/models/crossref.rb by rubocop

Tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method push_item has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.push_item(item)
    subj = cached_crossref_response(item["subj_id"])
    obj = cached_datacite_response(item["obj_id"])

    if ENV["STAFF_ADMIN_TOKEN"].present?
Severity: Minor
Found in app/models/crossref.rb - About 1 hr to fix

    Method queue_jobs has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def queue_jobs(options = {})
        options[:offset] = options[:offset].to_i || 0
        options[:rows] = options[:rows].presence || job_batch_size
        options[:from_date] =
          options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
    Severity: Minor
    Found in app/models/crossref.rb - About 1 hr to fix

      Method queue_jobs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def queue_jobs(options = {})
          options[:offset] = options[:offset].to_i || 0
          options[:rows] = options[:rows].presence || job_batch_size
          options[:from_date] =
            options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
      Severity: Minor
      Found in app/models/crossref.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

      Do not read from ENV directly post initialization.
      Open

          "#{ENV['CROSSREF_QUERY_URL']}/v1/events?#{URI.encode_www_form(params)}"
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Do not read from ENV directly post initialization.
      Open

            push_url = ENV["LAGOTTINO_URL"] + "/events/#{item['id']}"
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Do not read from ENV directly post initialization.
      Open

                                             bearer: ENV["STAFF_ADMIN_TOKEN"],
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Do not read from ENV directly post initialization.
      Open

          if ENV["STAFF_ADMIN_TOKEN"].present?
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

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

            elsif response.status == 409
              Rails.logger.info "[Event Data] #{item['subj_id']} #{item['relation_type_id']} #{item['obj_id']} already pushed to Event Data service."
            elsif response.body["errors"].present?
              Rails.logger.error "[Event Data] #{item['subj_id']} #{item['relation_type_id']} #{item['obj_id']} had an error: #{response.body['errors']}"
              Rails.logger.error data.inspect
      Severity: Major
      Found in app/models/crossref.rb and 1 other location - About 1 hr to fix
      app/jobs/usage_update_export_job.rb on lines 9..14

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

      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

      Line is too long. [147/120]
      Open

              Rails.logger.error "[Event Data] #{item['subj_id']} #{item['relation_type_id']} #{item['obj_id']} had an error: #{response.body['errors']}"
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

      This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

      If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

      • ArgumentAlignment
      • ArrayAlignment
      • BlockAlignment
      • BlockDelimiters
      • BlockEndNewline
      • ClosingParenthesisIndentation
      • FirstArgumentIndentation
      • FirstArrayElementIndentation
      • FirstHashElementIndentation
      • FirstParameterIndentation
      • HashAlignment
      • IndentationWidth
      • MultilineArrayLineBreaks
      • MultilineBlockLayout
      • MultilineHashBraceLayout
      • MultilineHashKeyLineBreaks
      • MultilineMethodArgumentLineBreaks
      • MultilineMethodParameterLineBreaks
      • ParameterAlignment

      Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

      Example:

      # bad
      {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
      
      # good
      {foo: "0000000000",
      bar: "0000000000", baz: "0000000000"}
      
      # good (with recommended cops enabled)
      {
        foo: "0000000000",
        bar: "0000000000",
        baz: "0000000000",
      }

      Line is too long. [146/120]
      Open

          # Rails.logger.info "Extracting related identifiers for #{items.size} DOIs updated from #{options[:from_date]} until #{options[:until_date]}."
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

      This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

      If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

      • ArgumentAlignment
      • ArrayAlignment
      • BlockAlignment
      • BlockDelimiters
      • BlockEndNewline
      • ClosingParenthesisIndentation
      • FirstArgumentIndentation
      • FirstArrayElementIndentation
      • FirstHashElementIndentation
      • FirstParameterIndentation
      • HashAlignment
      • IndentationWidth
      • MultilineArrayLineBreaks
      • MultilineBlockLayout
      • MultilineHashBraceLayout
      • MultilineHashKeyLineBreaks
      • MultilineMethodArgumentLineBreaks
      • MultilineMethodParameterLineBreaks
      • ParameterAlignment

      Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

      Example:

      # bad
      {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
      
      # good
      {foo: "0000000000",
      bar: "0000000000", baz: "0000000000"}
      
      # good (with recommended cops enabled)
      {
        foo: "0000000000",
        bar: "0000000000",
        baz: "0000000000",
      }

      Line is too long. [143/120]
      Open

              Rails.logger.info "[Event Data] #{item['subj_id']} #{item['relation_type_id']} #{item['obj_id']} already pushed to Event Data service."
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

      This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

      If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

      • ArgumentAlignment
      • ArrayAlignment
      • BlockAlignment
      • BlockDelimiters
      • BlockEndNewline
      • ClosingParenthesisIndentation
      • FirstArgumentIndentation
      • FirstArrayElementIndentation
      • FirstHashElementIndentation
      • FirstParameterIndentation
      • HashAlignment
      • IndentationWidth
      • MultilineArrayLineBreaks
      • MultilineBlockLayout
      • MultilineHashBraceLayout
      • MultilineHashKeyLineBreaks
      • MultilineMethodArgumentLineBreaks
      • MultilineMethodParameterLineBreaks
      • ParameterAlignment

      Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

      Example:

      # bad
      {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
      
      # good
      {foo: "0000000000",
      bar: "0000000000", baz: "0000000000"}
      
      # good (with recommended cops enabled)
      {
        foo: "0000000000",
        bar: "0000000000",
        baz: "0000000000",
      }

      Line is too long. [135/120]
      Open

              Rails.logger.info "[Event Data] #{item['subj_id']} #{item['relation_type_id']} #{item['obj_id']} pushed to Event Data service."
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

      This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

      If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

      • ArgumentAlignment
      • ArrayAlignment
      • BlockAlignment
      • BlockDelimiters
      • BlockEndNewline
      • ClosingParenthesisIndentation
      • FirstArgumentIndentation
      • FirstArrayElementIndentation
      • FirstHashElementIndentation
      • FirstParameterIndentation
      • HashAlignment
      • IndentationWidth
      • MultilineArrayLineBreaks
      • MultilineBlockLayout
      • MultilineHashBraceLayout
      • MultilineHashKeyLineBreaks
      • MultilineMethodArgumentLineBreaks
      • MultilineMethodParameterLineBreaks
      • ParameterAlignment

      Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

      Example:

      # bad
      {foo: "0000000000", bar: "0000000000", baz: "0000000000"}
      
      # good
      {foo: "0000000000",
      bar: "0000000000", baz: "0000000000"}
      
      # good (with recommended cops enabled)
      {
        foo: "0000000000",
        bar: "0000000000",
        baz: "0000000000",
      }

      Useless assignment to variable - count. Use _ or _count as a variable name to indicate that it won't be used.
      Open

              count, cursor = process_data(options)
      Severity: Minor
      Found in app/models/crossref.rb by rubocop

      Checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

      assigned but unused variable - foo

      Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

      Example:

      # bad
      
      def some_method
        some_var = 1
        do_something
      end

      Example:

      # good
      
      def some_method
        some_var = 1
        do_something(some_var)
      end

      There are no issues that match your filters.

      Category
      Status