Showing 215 of 228 total issues

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

              def handle_present_promotion
                return promotion_usage_limit_exceeded if promotion.usage_limit_exceeded?(order)
                return promotion_applied if promotion_exists_on_order?
        
                unless promotion.eligible?(order)
        Severity: Minor
        Found in core/app/models/spree/promotion_handler/coupon.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 line_item_actionable? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def line_item_actionable?(order, line_item)
              if eligible? order
                rules = eligible_rules(order)
                if rules.blank?
                  true
        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 refresh_rates has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def refresh_rates(shipping_method_filter = ShippingMethod::DISPLAY_ON_FRONT_END)
              return shipping_rates if shipped?
              return [] unless can_get_rates?
        
              # StockEstimator.new assignment below will replace the current shipping_method
        Severity: Minor
        Found in core/app/models/spree/shipment.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 verify has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def verify(shipment = nil, is_updated: false)
              return unless order.completed? || shipment.present?
        
              units_count = inventory_units.reload.sum(&:quantity)
              line_item_changed = is_updated ? !line_item.saved_changes? : !line_item.changed?
        Severity: Minor
        Found in core/app/models/spree/order_inventory.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 spree_storefront_resource_url has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def spree_storefront_resource_url(resource, options = {})
              if defined?(locale_param) && locale_param.present?
                options.merge!(locale: locale_param)
              end
        
        
        Severity: Minor
        Found in core/app/helpers/spree/base_helper.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 transfer_to_shipment has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                  def transfer_to_shipment
                    target_shipment = Spree::Shipment.find_by!(number: params.dig(:shipment, :target_shipment_number))
                    quantity = params.dig(:shipment, :quantity)&.to_i || 1
        
                    error =
        Severity: Minor
        Found in api/app/controllers/spree/api/v2/platform/shipments_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 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 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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            create_table "spree_products_stores", force: :cascade do |t|
              t.bigint "product_id"
              t.bigint "store_id"
              t.datetime "created_at", null: false
              t.datetime "updated_at", null: false
        Severity: Major
        Found in core/db/migrate/20210914000000_spree_four_three.rb and 1 other location - About 1 hr to fix
        core/db/migrate/20210914000000_spree_four_three.rb on lines 635..643

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 50.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            create_table "spree_promotions_stores", force: :cascade do |t|
              t.bigint "promotion_id"
              t.bigint "store_id"
              t.datetime "created_at", null: false
              t.datetime "updated_at", null: false
        Severity: Major
        Found in core/db/migrate/20210914000000_spree_four_three.rb and 1 other location - About 1 hr to fix
        core/db/migrate/20210914000000_spree_four_three.rb on lines 529..537

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 50.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method up_to has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.up_to(state, store = nil)
            store ||= if Spree::Store.exists?
                        # Ensure the default store is used
                        Spree::Store.default || FactoryBot.create(:store, default: true)
                      else
        Severity: Minor
        Found in core/lib/spree/testing_support/order_walkthrough.rb - About 1 hr to fix

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

            def change
              %i[
                spree_assets
                spree_option_types
                spree_option_values

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                create_table "spree_return_authorization_reasons", force: :cascade do |t|
                  t.string "name"
                  t.boolean "active", default: true
                  t.boolean "mutable", default: true
                  t.datetime "created_at", precision: 6, null: false
            Severity: Major
            Found in core/db/migrate/20210914000000_spree_four_three.rb and 1 other location - About 1 hr to fix
            core/db/migrate/20210914000000_spree_four_three.rb on lines 683..690

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 48.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                create_table "spree_refund_reasons", force: :cascade do |t|
                  t.string "name"
                  t.boolean "active", default: true
                  t.boolean "mutable", default: true
                  t.datetime "created_at", precision: 6, null: false
            Severity: Major
            Found in core/db/migrate/20210914000000_spree_four_three.rb and 1 other location - About 1 hr to fix
            core/db/migrate/20210914000000_spree_four_three.rb on lines 740..747

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 48.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

                def process_backorders(number)
                  return unless number.positive?
            
                  units = backordered_inventory_units.first(number) # We can process atmost n backorders
            
            
            Severity: Minor
            Found in core/app/models/spree/stock_item.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 preferred_tiers_content has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def preferred_tiers_content
                  if preferred_tiers.is_a? Hash
                    unless preferred_tiers.keys.all? { |k| k.is_a?(Numeric) && k > 0 }
                      errors.add(:base, :keys_should_be_positive_number)
                    end
            Severity: Minor
            Found in core/app/models/spree/calculator/tiered_percent.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