core/app/models/spree/product.rb

Summary

Maintainability
D
1 day
Test Coverage
A
96%

Class Product has 58 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Product < Spree::Base
    extend FriendlyId
    include Spree::ProductScopes
    include Spree::MultiStoreResource
    include Spree::TranslatableResource
Severity: Major
Found in core/app/models/spree/product.rb - About 1 day to fix

    File product.rb has 405 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Spree
      class Product < Spree::Base
        extend FriendlyId
        include Spree::ProductScopes
        include Spree::MultiStoreResource
    Severity: Minor
    Found in core/app/models/spree/product.rb - About 5 hrs to fix

      Method validate_master has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      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|
      Severity: Minor
      Found in core/app/models/spree/product.rb - About 45 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 set_property has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      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
      Severity: Minor
      Found in core/app/models/spree/product.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

      There are no issues that match your filters.

      Category
      Status