core/app/models/spree/product.rb
Class Product
has 58 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class Product < Spree::Base
extend FriendlyId
include Spree::ProductScopes
include Spree::MultiStoreResource
include Spree::TranslatableResource
File product.rb
has 405 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
module Spree
class Product < Spree::Base
extend FriendlyId
include Spree::ProductScopes
include Spree::MultiStoreResource
Method validate_master
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def validate_master
# We call master.default_price here to ensure price is initialized.
# Required to avoid Variant#check_price validation failing on create.
unless master.default_price && master.valid?
master.errors.map { |error| { field: error.attribute, message: error&.message } }.each do |err|
- 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_property
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def set_property(property_name, property_value, property_presentation = property_name)
ApplicationRecord.transaction do
# Manual first_or_create to work around Mobility bug
property = if Property.where(name: property_name).exists?
Property.where(name: property_name).first
- 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"