Showing 214 of 227 total issues

Method process_payments_with has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

        def process_payments_with(method)
          # Don't run if there is nothing to pay.
          return if payment_total >= total
          # Prevent orders from transitioning to complete without a successfully processed payment.
          raise Core::GatewayError, Spree.t(:no_payment_found) if unprocessed_payments.empty?
Severity: Minor
Found in core/app/models/spree/order/payments.rb - About 2 hrs 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 convert_preference_value has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def convert_preference_value(value, type)
    case type
    when :string, :text
      value.to_s
    when :password
Severity: Minor
Found in core/lib/spree/core/preferences/preferable.rb - About 2 hrs 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

Class BaseController has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

      class BaseController < ActionController::API
        include CanCan::ControllerAdditions
        include Spree::Core::ControllerHelpers::StrongParameters
        include Spree::Core::ControllerHelpers::Store
        include Spree::Core::ControllerHelpers::Locale
Severity: Minor
Found in api/app/controllers/spree/api/v2/base_controller.rb - About 2 hrs to fix

    Method state_validate has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def state_validate
          # Skip state validation without country (also required)
          # or when disabled by preference
          return if country.blank? || !Spree::Config[:address_requires_state]
          return unless country.states_required
    Severity: Minor
    Found in core/app/models/spree/address.rb - About 2 hrs 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 import has a Cognitive Complexity of 18 (exceeds 5 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 2 hrs 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

    Class Store has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Store < Spree::Base
        include Spree::TranslatableResource
        if defined?(Spree::Webhooks::HasWebhooks)
          include Spree::Webhooks::HasWebhooks
        end
    Severity: Minor
    Found in core/app/models/spree/store.rb - About 2 hrs to fix

      File product_scopes.rb has 258 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module Spree
        module ProductScopes
          extend ActiveSupport::Concern
      
          included do
      Severity: Minor
      Found in core/app/models/concerns/spree/product_scopes.rb - About 2 hrs to fix

        Class Zone has 21 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class Zone < Spree::Base
            include Spree::UniqueName
            if defined?(Spree::Webhooks::HasWebhooks)
              include Spree::Webhooks::HasWebhooks
            end
        Severity: Minor
        Found in core/app/models/spree/zone.rb - About 2 hrs to fix

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

              def contains?(target)
                return false if state? && target.country?
                return false if zone_members.empty? || target.zone_members.empty?
          
                if kind == target.kind
          Severity: Minor
          Found in core/app/models/spree/zone.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 insert_checkout_step has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

                    def self.insert_checkout_step(name, options = {})
                      before = options.delete(:before)
                      after = options.delete(:after) unless before
                      after = self.checkout_steps.keys.last unless before || after
          
          
          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

          Method add_french_locales has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def add_french_locales
                  I18n.backend.store_translations(:fr,
                    spree: {
                      added_to_cart: 'Ajouté au panier avec succès!',
                      continue_shopping: 'Continuer vos achats',
          Severity: Minor
          Found in core/lib/spree/testing_support/locale_helpers.rb - About 1 hr to fix

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

              def change
                # create translation table only if spree_globalize has not already created it
                if ActiveRecord::Base.connection.table_exists? 'spree_taxon_translations'
                  # manually check for index since Rails if_exists does not always work correctly
                  if ActiveRecord::Migration.connection.index_exists?(:spree_taxon_translations, :spree_taxon_id)
            core/db/migrate/20220706112554_create_product_name_and_description_translations_for_mobility_table_backend.rb on lines 2..26

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

            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 change
                # create translation table only if spree_globalize has not already created it
                if ActiveRecord::Base.connection.table_exists? 'spree_product_translations'
                  # manually check for index since Rails if_exists does not always work correctly
                  if ActiveRecord::Migration.connection.index_exists?(:spree_product_translations, :spree_product_id)
            core/db/migrate/20220718100743_create_spree_taxon_name_and_description_translations_for_mobility_table_backend.rb on lines 2..26

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

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

                  def default_package
                    package = Package.new(stock_location)
            
                    # Group by variant_id as grouping by variant fires cached query.
                    inventory_units.index_by(&:variant_id).each do |variant_id, inventory_unit|
            Severity: Minor
            Found in core/app/models/spree/stock/packer.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 change
                if ActiveRecord::Base.connection.table_exists? 'spree_product_property_translations'
                  # manually check for index since Rails if_exists does not always work correctly
                  if ActiveRecord::Migration.connection.index_exists?(:spree_product_property_translations, :spree_product_property_id)
                    remove_index :spree_product_property_translations, column: :spree_product_property_id, if_exists: true
            core/db/migrate/20230103151034_create_option_value_translations.rb on lines 2..25

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

            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 change
                if ActiveRecord::Base.connection.table_exists? 'spree_option_value_translations'
                  # manually check for index since Rails if_exists does not always work correctly
                  if ActiveRecord::Migration.connection.index_exists?(:spree_option_value_translations, :spree_option_value_id)
                    remove_index :spree_option_value_translations, column: :spree_option_value_id, if_exists: true
            core/db/migrate/20230109084253_create_product_property_translations.rb on lines 2..24

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

            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 convert_preference_value has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def convert_preference_value(value, type)
                case type
                when :string, :text
                  value.to_s
                when :password
            Severity: Minor
            Found in core/lib/spree/core/preferences/preferable.rb - About 1 hr to fix

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

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

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

                    def money_methods(*args)
                      args.each do |money_method|
                        money_method = { money_method => {} } unless money_method.is_a? Hash
                        money_method.each do |method_name, opts|
                          define_method("display_#{method_name}") do |**args_list|
                Severity: Minor
                Found in core/app/models/concerns/spree/display_money.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

                Severity
                Category
                Status
                Source
                Language