Showing 156 of 228 total issues

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

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

        def self.ensure_state_id_from_params(address)
          return if address.nil? || address[:state_id].present? || address[:state].nil?

          begin
            search = {}
Severity: Minor
Found in core/lib/spree/core/importer/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 ensure_country_id_from_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def self.ensure_country_id_from_params(address)
          return if address.nil? || address[:country_id].present? || address[:country].nil?

          begin
            search = {}
Severity: Minor
Found in core/lib/spree/core/importer/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 get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def get(key)
      # return the retrieved value, if it's in the cache
      # use unless nil? in case the value is actually boolean false
      #
      unless (val = @cache.read(key)).nil?
Severity: Minor
Found in core/lib/spree/core/preferences/store.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

Avoid too many return statements within this method.
Open

        return false if (target.states.pluck(:country_id) - countries.pluck(:id)).present?
Severity: Major
Found in core/app/models/spree/zone.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

              return if webhook_payload_body.blank?
    Severity: Major
    Found in api/app/models/concerns/spree/webhooks/has_webhooks.rb - About 30 mins to fix

      Method process_order_payments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def process_order_payments
            pending_payments = order.pending_payments.
                               sort_by(&:uncaptured_amount).reverse
      
            shipment_to_pay = final_price_with_items
      Severity: Minor
      Found in core/app/models/spree/shipment.rb - About 25 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 postal_code_validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def postal_code_validate
            return if country.blank? || country_iso.blank? || !require_zipcode? || zipcode.blank?
            return unless ::ValidatesZipcode::CldrRegexpCollection::ZIPCODES_REGEX.keys.include?(country_iso.upcase.to_sym)
      
            formatted_zip = ::ValidatesZipcode::Formatter.new(
      Severity: Minor
      Found in core/app/models/spree/address.rb - About 25 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_actions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def copy_actions
              @promotion.promotion_actions.each do |action|
                new_action = action.dup
                new_action.calculator = action.calculator.dup if action.try(:calculator)
      
      
      Severity: Minor
      Found in core/app/models/spree/promotion_handler/promotion_duplicator.rb - About 25 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 link_to_tracking has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def link_to_tracking(shipment, options = {})
            return unless shipment.tracking && shipment.shipping_method
      
            options[:target] ||= :blank
      
      
      Severity: Minor
      Found in core/app/helpers/spree/base_helper.rb - About 25 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 build_source has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def build_source
            return unless new_record?
      
            if source_attributes.present? && source.blank? && payment_method.try(:payment_source_class)
              self.source = payment_method.payment_source_class.new(source_attributes)
      Severity: Minor
      Found in core/app/models/spree/payment.rb - About 25 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 authorize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def authorize(amount, order_currency, options = {})
            authorization_code = options[:action_authorization_code]
            if authorization_code
              if store_credit_events.find_by(action: AUTHORIZE_ACTION, authorization_code: authorization_code)
                # Don't authorize again on capture
      Severity: Minor
      Found in core/app/models/spree/store_credit.rb - About 25 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 price_in has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def price_in(currency)
            currency = currency&.upcase
            find_or_build_price = lambda do
              if prices.loaded?
                prices.detect { |price| price.currency == currency } || prices.build(currency: currency)
      Severity: Minor
      Found in core/app/models/spree/variant.rb - About 25 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 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def change
          if table_exists?(:spree_wishlists)
            rename_column(:spree_wishlists, :access_hash, :token) if column_exists?(:spree_wishlists, :access_hash)
            add_reference(:spree_wishlists, :store, index: true) unless column_exists?(:spree_wishlists, :store_id)
          end
      Severity: Minor
      Found in core/db/migrate/20210921070812_rename_column_access_hash_to_token.rb - About 25 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 store_image_url_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

                def self.store_image_url_for(store, attribute_name)
                  attachment = store.send(attribute_name)&.attachment
                  return unless attachment&.attached?
      
                  url_helpers = Rails.application.routes.url_helpers
      Severity: Minor
      Found in api/app/helpers/spree/api/v2/store_media_serializer_images_concern.rb - About 25 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_rules has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def copy_rules
              @promotion.promotion_rules.each do |rule|
                new_rule = rule.dup
                @new_promotion.promotion_rules << new_rule
      
      
      Severity: Minor
      Found in core/app/models/spree/promotion_handler/promotion_duplicator.rb - About 25 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 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def change
          create_table :spree_wished_products, if_not_exists: true do |t|
            t.references :variant
            t.belongs_to :wishlist
      
      
      Severity: Minor
      Found in core/db/migrate/20210921070814_create_spree_wished_products.rb - About 25 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 reset_multiple_link_attributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def reset_multiple_link_attributes
            if link_type_one_changed?
              return if link_type_one_was.nil?
      
              self.link_one = nil
      Severity: Minor
      Found in core/app/models/spree/cms/sections/side_by_side_images.rb - About 25 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 ordered has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def ordered(products)
              return products unless sort_by?
      
              case sort_by
              when 'default'
      Severity: Minor
      Found in core/app/finders/spree/products/find.rb - About 25 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