Showing 156 of 228 total issues

Method redirect_unauthorized_access has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

        def redirect_unauthorized_access
          Spree::Deprecation.warn(<<-DEPRECATION, caller)
            Core::ControllerHelpers#redirect_unauthorized_access is deprecated and will be removed in Spree 5.0.
            This method is implemented differently for Storefront and Admin
          DEPRECATION
Severity: Minor
Found in core/lib/spree/core/controller_helpers/auth.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 fill_status has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def fill_status(variant, quantity)
      if item = stock_item_or_create(variant)
        if item.count_on_hand >= quantity
          on_hand = quantity
          backordered = 0
Severity: Minor
Found in core/app/models/spree/stock_location.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 handle_payment_preconditions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def handle_payment_preconditions
        unless block_given?
          raise ArgumentError, 'handle_payment_preconditions must be called with a block'
        end

Severity: Minor
Found in core/app/models/spree/payment/processing.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_shipments_from_params has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

        def self.create_shipments_from_params(shipments_hash, order)
          return [] unless shipments_hash

          shipments_hash.each do |s|
            shipment = order.shipments.build
Severity: Minor
Found in core/lib/spree/core/importer/order.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 apply_user_permissions has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def apply_user_permissions(user)
      can :read, ::Spree::Country
      can :read, ::Spree::Menu
      can :read, ::Spree::CmsPage
      can :read, ::Spree::OptionType
Severity: Minor
Found in core/app/models/spree/ability.rb - About 1 hr to fix

    Method down has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def down
        ActiveRecord::Base.connection.execute("
          UPDATE #{PRODUCTS_TABLE} as products
          SET (name,
               description,

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

                def title
                  Spree::Deprecation.warn(<<-DEPRECATION, caller)
                    ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.
                  DEPRECATION
                  title_string = @title.present? ? @title : accurate_title
      Severity: Minor
      Found in core/lib/spree/core/controller_helpers/common.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 link has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def link
              case linked_resource_type
              when 'Spree::Taxon'
                return if linked_resource&.permalink.blank?
      
      
      Severity: Minor
      Found in core/app/models/concerns/spree/display_link.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 queue_webhooks_requests! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              def queue_webhooks_requests!(event_name)
                return if disable_spree_webhooks?
                return if Spree::Webhooks::Subscriber.none?
                return if Spree::Webhooks::Subscriber.active.with_urls_for(event_name).none?
                return if update_event?(event_name) && updating_only_ignored_attributes?
      Severity: Minor
      Found in api/app/models/concerns/spree/webhooks/has_webhooks.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 display_getter_methods has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              def self.display_getter_methods(model_klazz)
                model_klazz.new.methods.find_all do |method_name|
                  next unless method_name.to_s.start_with?('display_')
                  next if method_name.to_s.end_with?('=')
                  next if [Spree::Product, Spree::Variant].include?(model_klazz) && method_name == :display_amount

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

              def eligible?(order, _options = {})
                return true if eligible_products.empty?
      
                if preferred_match_policy == 'all'
                  unless eligible_products.all? { |p| order.products.include?(p) }
      Severity: Minor
      Found in core/app/models/spree/promotion/rules/product.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_payments_from_params has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

              def self.create_payments_from_params(payments_hash, order)
                return [] unless payments_hash
      
                payments_hash.each do |p|
                  payment = order.payments.build order: order
      Severity: Minor
      Found in core/lib/spree/core/importer/order.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 load_samples has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.load_samples
            Spree::Webhooks.disable_webhooks do
              Spree::Sample.load_sample('addresses')
              Spree::Sample.load_sample('zones')
              Spree::Sample.load_sample('payment_methods')
      Severity: Minor
      Found in sample/lib/spree_sample.rb - About 1 hr to fix

        Method create_shipments_from_params has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def self.create_shipments_from_params(shipments_hash, order)
                  return [] unless shipments_hash
        
                  shipments_hash.each do |s|
                    shipment = order.shipments.build
        Severity: Minor
        Found in core/lib/spree/core/importer/order.rb - About 1 hr to fix

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

                  def self.import(user, params)
                    ensure_country_id_from_params params[:ship_address_attributes]
                    ensure_state_id_from_params params[:ship_address_attributes]
                    ensure_country_id_from_params params[:bill_address_attributes]
                    ensure_state_id_from_params params[:bill_address_attributes]
          Severity: Minor
          Found in core/lib/spree/core/importer/order.rb - About 1 hr to fix

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

              def change
                remove_index :spree_stock_items, name: 'stock_item_by_loc_var_id_deleted_at' if index_exists?(:spree_stock_items, [:stock_location_id, :variant_id], name: 'stock_item_by_loc_var_id_deleted_at')
            
                unless index_exists?(:spree_stock_items, ['variant_id', 'stock_location_id'], name: 'index_spree_stock_items_unique_without_deleted_at')
                  # MySQL doesn't support partial indexes
            Severity: Minor
            Found in core/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb - About 1 hr to fix

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

                  def generate
                    use_prefix 'spree_'
              
                    empty_directory file_name
              
              
              Severity: Minor
              Found in cli/lib/spree_cli/extension.rb - About 1 hr to fix

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

                          def download
                            if attachment.present?
                              if digital_link.authorize!
                                if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService)
                                  # The asset is hosted on disk, use send_file.
                Severity: Minor
                Found in api/app/controllers/spree/api/v2/storefront/digitals_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 eligible_rules has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    def eligible_rules(promotable, options = {})
                      # Promotions without rules are eligible by default.
                      return [] if rules.none?
                
                      specific_rules = rules.select { |rule| rule.applicable?(promotable) }
                Severity: Minor
                Found in core/app/models/spree/promotion.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_params_payment_source has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                          def update_params_payment_source
                            if @updating_params[:payment_source].present?
                              source_params = @updating_params.
                                              delete(:payment_source)[@updating_params[:order][:payments_attributes].
                                              first[:payment_method_id].to_s]
                Severity: Minor
                Found in core/app/models/spree/order/checkout.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

                Severity
                Category
                Status
                Source
                Language