Showing 211 of 224 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?
- Read upRead up
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
- Read upRead up
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
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]
- Read upRead up
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 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
- Read upRead up
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
File product_scopes.rb
has 257 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Spree
module ProductScopes
extend ActiveSupport::Concern
included do
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
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
- Read upRead up
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 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
- Read upRead up
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',
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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|
- Read upRead up
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 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
Method update_payment_state
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def update_payment_state
last_state = order.payment_state
if payments.present? && payments.valid.empty?
order.payment_state = 'failed'
elsif order.canceled? && order.payment_total == 0
- Read upRead up
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 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|
- Read upRead up
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?
- Read upRead up
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 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
- Read upRead up
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]
- Read upRead up
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"