Showing 156 of 228 total issues

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

        def self.create_line_items_from_params(line_items, order)
          return {} unless line_items

          line_items.each do |line_item|
            adjustments = line_item.delete(:adjustments_attributes)
Severity: Minor
Found in core/lib/spree/core/importer/order.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

Consider simplifying this complex logical expression.
Open

      if value.is_a?(FalseClass) ||
          value.nil? ||
          value == 0 ||
          value&.to_s =~ /^(f|false|0)$/i ||
          (value.respond_to?(:empty?) && value.empty?)
Severity: Major
Found in core/lib/spree/core/preferences/preferable.rb - About 40 mins to fix

    Method process_spree_xhr_action has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def process_spree_xhr_action(action, parameters = nil, session = nil, flash = nil, method = :get)
    Severity: Minor
    Found in core/lib/spree/testing_support/controller_requests.rb - About 35 mins to fix

      Method create_refunds has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def create_refunds(reimbursement, payments, unpaid_amount, simulate, reimbursement_list = [])
      Severity: Minor
      Found in core/app/models/spree/reimbursement_type/reimbursement_helpers.rb - About 35 mins to fix

        Method process_spree_action has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def process_spree_action(action, parameters = nil, session = nil, flash = nil, method = 'GET')
        Severity: Minor
        Found in core/lib/spree/testing_support/controller_requests.rb - About 35 mins to fix

          Method eligible? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def eligible?(order, options = {})
                    @user = order.try(:user) || options[:user]
                    @email = order.email
                    @store = order.store
          
          
          Severity: Minor
          Found in core/app/models/spree/promotion/rules/first_order.rb - About 35 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 og_meta_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def og_meta_data
                og_meta = {}
          
                if object.is_a? Spree::Product
                  image                             = default_image_for_product_or_variant(object)
          Severity: Minor
          Found in core/app/helpers/spree/base_helper.rb - About 35 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 remove_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def remove_item(shipment:, variant:, quantity:)
                  result = remove_item_service.call(order: shipment.order,
                                                    variant: variant,
                                                    quantity: quantity,
                                                    options: { shipment: shipment })
          Severity: Minor
          Found in core/app/services/spree/shipments/remove_item.rb - About 35 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 validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def validate(line_item)
                  unit_count = line_item.inventory_units.reject(&:pending?).sum(&:quantity)
                  return if unit_count >= line_item.quantity
          
                  quantity = line_item.quantity - unit_count
          Severity: Minor
          Found in core/app/models/spree/stock/availability_validator.rb - About 35 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 validate_source has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate_source
                if source && !source.valid?
                  source.errors.map { |error| { field: error.attribute, message: error&.message } }.each do |err|
                    next if err[:field].blank? || err[:message].blank?
          
          
          Severity: Minor
          Found in core/app/models/spree/payment.rb - About 35 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 update_or_create_address has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def update_or_create_address(attributes = {})
                  return if attributes.blank?
          
                  attributes.transform_values! { |v| v == '' ? nil : v }
                  attributes = attributes.to_h.symbolize_keys
          Severity: Minor
          Found in core/app/models/spree/order/address_book.rb - About 35 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 copy_price has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def copy_price
                if variant
                  update_price if price.nil?
                  self.cost_price = variant.cost_price if cost_price.nil?
                  self.currency = variant.currency if currency.nil?
          Severity: Minor
          Found in core/app/models/spree/line_item.rb - About 35 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 capture has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def capture(amount, authorization_code, order_currency, options = {})
                return false unless authorize(amount, order_currency, action_authorization_code: authorization_code)
          
                if amount <= amount_authorized
                  if currency != order_currency
          Severity: Minor
          Found in core/app/models/spree/store_credit.rb - About 35 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 default_image_for_product_or_variant has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def default_image_for_product_or_variant(product_or_variant)
                Rails.cache.fetch("spree/default-image/#{product_or_variant.cache_key_with_version}") do
                  if product_or_variant.is_a?(Spree::Product)
                    default_image_for_product(product_or_variant)
                  elsif product_or_variant.is_a?(Spree::Variant)
          Severity: Minor
          Found in core/app/helpers/spree/base_helper.rb - About 35 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 change has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def change
              if Spree.user_class.present?
                users_table_name = Spree.user_class.table_name
                add_column users_table_name, :first_name, :string unless column_exists?(users_table_name, :first_name)
                add_column users_table_name, :last_name, :string unless column_exists?(users_table_name, :last_name)

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

              def calculate_reimbursement_type(return_item)
                return exchange_reimbursement_type if return_item.exchange_required?
                return return_item.override_reimbursement_type.class if return_item.override_reimbursement_type.present?
                if return_item.preferred_reimbursement_type.present?
                  return valid_preferred_reimbursement_type?(return_item) ? return_item.preferred_reimbursement_type.class : nil
          Severity: Minor
          Found in core/app/models/spree/reimbursement/reimbursement_type_engine.rb - About 35 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 void_transaction! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def void_transaction!
                  return true if void?
          
                  protect_from_connection_error do
                    if payment_method.payment_profiles_supported?
          Severity: Minor
          Found in core/app/models/spree/payment/processing.rb - About 35 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 available has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def self.available(available_on = nil, currency = nil)
                  if available_on
                    scope = not_discontinued.where("#{Product.quoted_table_name}.available_on <= ?", available_on)
                  else
                    scope = where(status: 'active')
          Severity: Minor
          Found in core/app/models/concerns/spree/product_scopes.rb - About 35 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 searcher_class has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.searcher_class(constantize: true)
              @@searcher_class ||= 'Spree::Core::Search::Base'
          
              if @@searcher_class.is_a?(Class)
                raise 'Spree.searcher_class MUST be a String or Symbol object, not a Class object.'
          Severity: Minor
          Found in core/lib/spree/core.rb - About 35 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 apply has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def apply
                  if order.coupon_code.present?
                    if promotion.present? && promotion.actions.exists?
                      handle_present_promotion
                    elsif store.promotions.with_coupon_code(order.coupon_code).try(:expired?)
          Severity: Minor
          Found in core/app/models/spree/promotion_handler/coupon.rb - About 35 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