core/app/models/spree/variant.rb

Summary

Maintainability
C
1 day
Test Coverage
A
93%

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
Severity: Minor
Found in core/app/models/spree/variant.rb - About 5 hrs to fix

    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
    
    
    Severity: Minor
    Found in core/app/models/spree/variant.rb - About 3 hrs to fix

      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
      
      
      Severity: Minor
      Found in core/app/models/spree/variant.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_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|
      Severity: Minor
      Found in core/app/models/spree/variant.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 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)
      Severity: Minor
      Found in core/app/models/spree/variant.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