Class Variant
has 41 methods (exceeds 20 allowed). Consider refactoring. Open
class Variant < Spree::Base
acts_as_paranoid
acts_as_list scope: :product
include Spree::MemoizedData
File variant.rb
has 298 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Spree
class Variant < Spree::Base
acts_as_paranoid
acts_as_list scope: :product
Method check_price
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def check_price
if price.nil? && Spree::Config[:require_master_price]
return errors.add(:base, :no_master_variant_found_to_infer_price) unless product&.master
return errors.add(:base, :must_supply_price_for_variant_or_master) if self == product.master
- 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 set_option_value
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def set_option_value(opt_name, opt_value)
# no option values on master
return if is_master
option_type = Spree::OptionType.where(['LOWER(name) = ?', opt_name.downcase.strip]).first_or_initialize do |o|
- 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 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)
- 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"