datacite/levriero

View on GitHub
app/models/crossref_orcid.rb

Summary

Maintainability
B
6 hrs
Test Coverage
B
87%

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

  def self.push_item(item)
    doi = item.fetch("DOI", nil)
    return nil if doi.blank?

    pid = normalize_doi(doi)
Severity: Major
Found in app/models/crossref_orcid.rb - About 2 hrs to fix

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

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

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

      def self.push_item(item)
        doi = item.fetch("DOI", nil)
        return nil if doi.blank?
    
        pid = normalize_doi(doi)
    Severity: Minor
    Found in app/models/crossref_orcid.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 queue_jobs has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

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

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

        def queue_jobs(options = {})
          options[:rows] = options[:rows].presence || job_batch_size
          options[:from_date] =
            options[:from_date].presence || (Time.now.to_date - 1.day).iso8601
          options[:until_date] =
      Severity: Minor
      Found in app/models/crossref_orcid.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 push_item has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.push_item(item)
          doi = item.fetch("DOI", nil)
          return nil if doi.blank?
      
          pid = normalize_doi(doi)
      Severity: Minor
      Found in app/models/crossref_orcid.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

      Block has too many lines. [33/25]
      Open

          Array.wrap(push_items).each do |iiitem|
            if ENV["STAFF_ADMIN_TOKEN"].present?
              push_url = "#{ENV['LAGOTTINO_URL']}/events"
      
              data = {
      Severity: Minor
      Found in app/models/crossref_orcid.rb by rubocop

      Checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

      You can set constructs you want to fold with CountAsOne. Available are: 'array', 'hash', 'heredoc', and 'method_call'. Each construct will be counted as one line regardless of its actual size.

      NOTE: The ExcludedMethods configuration is deprecated and only kept for backwards compatibility. Please use AllowedMethods and AllowedPatterns instead. By default, there are no methods to allowed.

      Example: CountAsOne: ['array', 'heredoc', 'method_call']

      something do
        array = [         # +1
          1,
          2
        ]
      
        hash = {          # +3
          key: 'value'
        }
      
        msg = <<~HEREDOC  # +1
          Heredoc
          content.
        HEREDOC
      
        foo(              # +1
          1,
          2
        )
      end                 # 6 points

      NOTE: This cop does not apply for Struct definitions.

      Do not read from ENV directly post initialization.
      Open

          source_token = ENV["CROSSREF_ORCID_AUTO_UPDATE_SOURCE_TOKEN"]
      Severity: Minor
      Found in app/models/crossref_orcid.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_orcid.rb by rubocop

      Do not read from ENV directly post initialization.
      Open

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

      Do not read from ENV directly post initialization.
      Open

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

      Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
      Open

              if [200, 201].include?(response.status)
      Severity: Minor
      Found in app/models/crossref_orcid.rb by rubocop

      Line is too long. [155/120]
      Open

                Rails.logger.error "[Event Data] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} had an error: #{response.body['errors']}"
      Severity: Minor
      Found in app/models/crossref_orcid.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. [151/120]
      Open

                Rails.logger.info "[Event Data] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} already pushed to Event Data service."
      Severity: Minor
      Found in app/models/crossref_orcid.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] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} pushed to Event Data service."
      Severity: Minor
      Found in app/models/crossref_orcid.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_orcid.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