algolia/algoliasearch-rails

View on GitHub

Showing 31 of 31 total issues

File algoliasearch-rails.rb has 847 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'algolia'

require 'algoliasearch/version'
require 'algoliasearch/utilities'

Severity: Major
Found in lib/algoliasearch-rails.rb - About 2 days to fix

    Method algoliasearch has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        def algoliasearch(options = {}, &block)
          self.algoliasearch_settings = IndexSettings.new(options, &block)
          self.algoliasearch_options = { :type => algolia_full_const_get(model_name.to_s), :per_page => algoliasearch_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options)
    
          attr_accessor :highlight_result, :snippet_result
    Severity: Minor
    Found in lib/algoliasearch-rails.rb - About 6 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 extended has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.extended(base)
          class <<base
            alias_method :without_auto_index, :algolia_without_auto_index unless method_defined? :without_auto_index
            alias_method :reindex!, :algolia_reindex! unless method_defined? :reindex!
            alias_method :reindex, :algolia_reindex unless method_defined? :reindex
    Severity: Minor
    Found in lib/algoliasearch-rails.rb - About 4 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 algoliasearch has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def algoliasearch(options = {}, &block)
          self.algoliasearch_settings = IndexSettings.new(options, &block)
          self.algoliasearch_options = { :type => algolia_full_const_get(model_name.to_s), :per_page => algoliasearch_settings.get_setting(:hitsPerPage) || 10, :page => 1 }.merge(options)
    
          attr_accessor :highlight_result, :snippet_result
    Severity: Major
    Found in lib/algoliasearch-rails.rb - About 3 hrs to fix

      Method algolia_index! has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_index!(object, synchronous = false)
            return if algolia_without_auto_index_scope
            algolia_configurations.each do |options, settings|
              next if algolia_indexing_disabled?(options)
              object_id = algolia_object_id_of(object, options)
      Severity: Minor
      Found in lib/algoliasearch-rails.rb - About 3 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 algolia_ensure_init has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_ensure_init(options = nil, settings = nil, index_settings = nil)
            raise ArgumentError.new('No `algoliasearch` block found in your model.') if algoliasearch_settings.nil?
      
            @algolia_indexes ||= {}
      
      
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algolia_reindex has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
            return if algolia_without_auto_index_scope
            algolia_configurations.each do |options, settings|
              next if algolia_indexing_disabled?(options)
              next if options[:replica]
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algolia_reindex! has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_reindex!(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
            return if algolia_without_auto_index_scope
            algolia_configurations.each do |options, settings|
              next if algolia_indexing_disabled?(options)
              index = algolia_ensure_init(options, settings)
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algolia_must_reindex? has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_must_reindex?(object)
            # use +algolia_dirty?+ method if implemented
            return object.send(:algolia_dirty?) if (object.respond_to?(:algolia_dirty?))
            # Loop over each index to see if a attribute used in records has changed
            algolia_configurations.each do |options, settings|
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algoliasearch_settings_changed? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def algoliasearch_settings_changed?(prev, current)
            return true if prev.nil?
            current.each do |k, v|
              prev_v = prev[k.to_s]
              if v.is_a?(Array) and prev_v.is_a?(Array)
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algolia_remove_from_index! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def algolia_remove_from_index!(object, synchronous = false)
            return if algolia_without_auto_index_scope
            object_id = algolia_object_id_of(object)
            raise ArgumentError.new("Cannot index a record with a blank objectID") if object_id.blank?
            algolia_configurations.each do |options, settings|
      Severity: Minor
      Found in lib/algoliasearch-rails.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 algolia_reindex has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
            return if algolia_without_auto_index_scope
            algolia_configurations.each do |options, settings|
              next if algolia_indexing_disabled?(options)
              next if options[:replica]
      Severity: Minor
      Found in lib/algoliasearch-rails.rb - About 1 hr to fix

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

            def algolia_search(q, params = {})
              if AlgoliaSearch.configuration[:pagination_backend]
                # kaminari, will_paginate, and pagy start pagination at 1, Algolia starts at 0
                params[:page] = (params.delete('page') || params.delete(:page)).to_i
                params[:page] -= 1 if params[:page].to_i > 0
        Severity: Minor
        Found in lib/algoliasearch-rails.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 to_settings has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def to_settings
              settings = {}
              OPTIONS.each do |k|
                v = get_setting(k)
                settings[k] = v if !v.nil?
        Severity: Minor
        Found in lib/algoliasearch-rails.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 algolia_find_in_batches has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def algolia_find_in_batches(batch_size, &block)
              if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
                find_in_batches(:batch_size => batch_size, &block)
              elsif defined?(::Sequel) && defined?(::Sequel::Model) && self < Sequel::Model
                dataset.extension(:pagination).each_page(batch_size, &block)
        Severity: Minor
        Found in lib/algoliasearch-rails.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_attributes has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_attributes(object)
              # If a serializer is set, we ignore attributes
              # everything should be done via the serializer
              if not @serializer.nil?
                attributes = @serializer.new(object).attributes
        Severity: Minor
        Found in lib/algoliasearch-rails.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 algolia_search has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def algolia_search(q, params = {})
              if AlgoliaSearch.configuration[:pagination_backend]
                # kaminari, will_paginate, and pagy start pagination at 1, Algolia starts at 0
                params[:page] = (params.delete('page') || params.delete(:page)).to_i
                params[:page] -= 1 if params[:page].to_i > 0
        Severity: Minor
        Found in lib/algoliasearch-rails.rb - About 1 hr to fix

          Method get_attributes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def get_attributes(object)
                # If a serializer is set, we ignore attributes
                # everything should be done via the serializer
                if not @serializer.nil?
                  attributes = @serializer.new(object).attributes
          Severity: Minor
          Found in lib/algoliasearch-rails.rb - About 1 hr to fix

            Method algolia_clear_index! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def algolia_clear_index!(synchronous = false)
                  algolia_configurations.each do |options, settings|
                    next if algolia_indexing_disabled?(options)
                    index = algolia_ensure_init(options, settings)
                    next if options[:replica]
            Severity: Minor
            Found in lib/algoliasearch-rails.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 algolia_index_objects has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def algolia_index_objects(objects, synchronous = false)
                  algolia_configurations.each do |options, settings|
                    next if algolia_indexing_disabled?(options)
                    index = algolia_ensure_init(options, settings)
                    next if options[:replica]
            Severity: Minor
            Found in lib/algoliasearch-rails.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

            Severity
            Category
            Status
            Source
            Language