Showing 214 of 227 total issues

Method call has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def call(order:, params:)
        if params[:shipment_id].present?
          shipment = order.shipments.valid.find_by(id: params[:shipment_id])
          return failure(:shipment_not_found) if shipment.nil?
        end
Severity: Minor
Found in core/app/services/spree/checkout/select_shipping_method.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 meta_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def meta_data
      meta = {}

      if object.is_a? ApplicationRecord
        meta[:keywords] = object.meta_keywords if object.try(:meta_keywords).present?
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 populate_seed_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def populate_seed_data
      if @load_seed_data
        say_status :loading,  'seed data'
        rake_options = []
        rake_options << 'AUTO_ACCEPT=1' if options[:auto_accept]
Severity: Minor
Found in core/lib/generators/spree/install/install_generator.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 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 by_properties has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def by_properties(products)
        return products unless properties?

        product_ids = []
        index = 0
Severity: Minor
Found in core/app/finders/spree/products/find.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

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

    def cancel_email(order, resend = false)
      @order = order.respond_to?(:id) ? order : Spree::Order.find(order)
      current_store = @order.store
      subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
      subject += "#{current_store.name} #{Spree.t('order_mailer.cancel_email.subject')} ##{@order.number}"
Severity: Major
Found in emails/app/mailers/spree/order_mailer.rb and 1 other location - About 1 hr to fix
emails/app/mailers/spree/order_mailer.rb on lines 3..8

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 58.

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

    def confirm_email(order, resend = false)
      @order = order.respond_to?(:id) ? order : Spree::Order.find(order)
      current_store = @order.store
      subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
      subject += "#{current_store.name} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}"
Severity: Major
Found in emails/app/mailers/spree/order_mailer.rb and 1 other location - About 1 hr to fix
emails/app/mailers/spree/order_mailer.rb on lines 18..23

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 58.

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 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 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 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 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 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 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 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 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
          Severity
          Category
          Status
          Source
          Language