datacite/lupo

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

Summary

Maintainability
F
1 wk
Test Coverage
F
10%

Method query has a Cognitive Complexity of 194 (exceeds 5 allowed). Consider refactoring.
Open

    def query(query, options = {})
      # support scroll api
      # map function is small performance hit
      if options[:scroll_id].present? && options.dig(:page, :scroll)
        begin
Severity: Minor
Found in app/models/concerns/indexable.rb - About 3 days 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 query has 548 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def query(query, options = {})
      # support scroll api
      # map function is small performance hit
      if options[:scroll_id].present? && options.dig(:page, :scroll)
        begin
Severity: Major
Found in app/models/concerns/indexable.rb - About 2 days to fix

    File indexable.rb has 966 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Indexable
      extend ActiveSupport::Concern
    
      require "aws-sdk-sqs"
    
    
    Severity: Major
    Found in app/models/concerns/indexable.rb - About 2 days to fix

      Method switch_index has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def switch_index(options = {})
            alias_name = options[:alias] || index_name
            index_name = (options[:index] || self.index_name) + "_v1"
            alternate_index_name = (options[:index] || self.index_name) + "_v2"
            is_write_index = options[:is_write_index] || name != "OtherDoi"
      Severity: Minor
      Found in app/models/concerns/indexable.rb - About 1 hr to fix

        Method create_template has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def create_template
              alias_name = index_name
        
              body =
                if name == "Doi" || name == "DataciteDoi" || name == "OtherDoi"
        Severity: Minor
        Found in app/models/concerns/indexable.rb - About 1 hr to fix

          Method active_index has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def active_index
                ret = nil
          
                alias_name = index_name
                client = Elasticsearch::Model.client
          Severity: Minor
          Found in app/models/concerns/indexable.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 create_index has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_index(options = {})
                alias_name = options[:alias] || index_name
                index_name = (options[:index] || self.index_name) + "_v1"
                alternate_index_name = (options[:index] || self.index_name) + "_v2"
                client = Elasticsearch::Model.client
          Severity: Minor
          Found in app/models/concerns/indexable.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 create_template has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_template
                alias_name = index_name
          
                body =
                  if name == "Doi" || name == "DataciteDoi" || name == "OtherDoi"
          Severity: Minor
          Found in app/models/concerns/indexable.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

          Avoid deeply nested control flow statements.
          Open

                  if options[:client_id].present?
                    options[:client_id].split(",").each { |id|
                      should << { term: { "client_ids": { value: id, case_insensitive: true } } }
                    }
                    minimum_should_match = 1
          Severity: Major
          Found in app/models/concerns/indexable.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                  elsif name == "ProviderPrefix"
                    must =
                      if query.present?
                        [{ prefix: { prefix_id: query } }]
                      else
            Severity: Major
            Found in app/models/concerns/indexable.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                      if options[:year].present?
                        filter <<
                          {
                            range: {
                              created_at: {
              Severity: Major
              Found in app/models/concerns/indexable.rb - About 45 mins to fix

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

                    def send_message(body, options = {})
                      sqs = Aws::SQS::Client.new
                      queue_name_prefix =
                        if Rails.env.stage?
                          ENV["ES_PREFIX"].present? ? "stage" : "test"
                Severity: Minor
                Found in app/models/concerns/indexable.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

                Avoid deeply nested control flow statements.
                Open

                          query.present? ? [{ prefix: { prefix: query } }] : [{ match_all: {} }]
                Severity: Major
                Found in app/models/concerns/indexable.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if options[:state].present?
                            filter << { terms: { state: options[:state].to_s.split(",") } }
                          end
                  Severity: Major
                  Found in app/models/concerns/indexable.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if options[:provider_id].present?
                              options[:provider_id].split(",").each { |id|
                                should << { term: { "provider_ids": { value: id, case_insensitive: true } } }
                              }
                              minimum_should_match = 1
                    Severity: Major
                    Found in app/models/concerns/indexable.rb - About 45 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status