ngelx/solidus_import_products

View on GitHub
app/services/solidus_import_products/create_variant.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Assignment Branch Condition size for call is too high. [41.3/15]
Open

    def call(args = { product: nil, product_information: nil })
      self.logger = SolidusImportProducts::Logger.instance
      self.product_information = args[:product_information]
      self.product = args[:product]
      return if product_information.nil?

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for stock_items is too high. [32.62/15]
Open

    def stock_items
      source_location = Spree::StockLocation.find_by(default: true)
      unless source_location
        logger.log('Seems that there are no SourceLocation set right?, so stock will not set.', :warn) if product_information[:attributes][:stock] || product_information[:attributes][:backorderable]
        return

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for load_or_initialize_variant is too high. [30.13/15]
Open

    def load_or_initialize_variant
      self.variant = Spree::Variant.find_by(sku: product_information[:attributes][:sku])

      if variant
        if variant.product != product

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Cyclomatic complexity for stock_items is too high. [7/6]
Open

    def stock_items
      source_location = Spree::StockLocation.find_by(default: true)
      unless source_location
        logger.log('Seems that there are no SourceLocation set right?, so stock will not set.', :warn) if product_information[:attributes][:stock] || product_information[:attributes][:backorderable]
        return

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method call has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def call(args = { product: nil, product_information: nil })
      self.logger = SolidusImportProducts::Logger.instance
      self.product_information = args[:product_information]
      self.product = args[:product]
      return if product_information.nil?
Severity: Minor
Found in app/services/solidus_import_products/create_variant.rb - About 1 hr to fix

    Method call has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def call(args = { product: nil, product_information: nil })
          self.logger = SolidusImportProducts::Logger.instance
          self.product_information = args[:product_information]
          self.product = args[:product]
          return if product_information.nil?
    Severity: Minor
    Found in app/services/solidus_import_products/create_variant.rb - About 55 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 stock_items has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def stock_items
          source_location = Spree::StockLocation.find_by(default: true)
          unless source_location
            logger.log('Seems that there are no SourceLocation set right?, so stock will not set.', :warn) if product_information[:attributes][:stock] || product_information[:attributes][:backorderable]
            return
    Severity: Minor
    Found in app/services/solidus_import_products/create_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 options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def options(field, value)
          return unless value
    
          option_type = get_or_create_option_type(field)
          option_value = get_or_create_option_value(option_type, value)
    Severity: Minor
    Found in app/services/solidus_import_products/create_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

    Line is too long. [198/130]
    Open

            logger.log('Seems that there are no SourceLocation set right?, so stock will not set.', :warn) if product_information[:attributes][:stock] || product_information[:attributes][:backorderable]

    Line is too long. [190/130]
    Open

          stock_item.send('backorderable=', product_information[:attributes][:backorderable]) if product_information[:attributes].key?(:backorderable) && stock_item.respond_to?('backorderable=')

    Extra empty line detected at block body beginning.
    Open

    
          end

    This cops checks if empty lines around the bodies of blocks match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    foo do |bar|
    
      # ...
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    foo do |bar|
      # ...
    end

    Line is too long. [135/130]
    Open

                    "SKU #{product_information[:attributes][:sku]} should belongs to #{product.inspect} but was #{variant.product.inspect}"

    Line is too long. [131/130]
    Open

            self.variant = product.variants.new(sku: product_information[:attributes][:sku], id: product_information[:attributes][:id])

    Line is too long. [133/130]
    Open

              value.each { |attr_field, attr_value| variant.send("#{attr_field}=", attr_value) if variant.respond_to?("#{attr_field}=") }

    There are no issues that match your filters.

    Category
    Status