public-market/spree_batch_api

View on GitHub
app/actions/spree/inventory/providers/default_variant_provider.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class DefaultVariantProvider has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

      class DefaultVariantProvider < Spree::BaseAction # rubocop:disable Metrics/ClassLength
        KEYWORDS_DELIMITER = ' '.freeze
        VALIDATION_SCHEMA =
          ::Dry::Validation.Schema do
            required(:sku).filled(:str?)
Severity: Minor
Found in app/actions/spree/inventory/providers/default_variant_provider.rb - About 4 hrs to fix

    Assignment Branch Condition size for update_variant is too high. [17.52/15]
    Open

            def update_variant(variant, item)
              variant.price = variant.cost_price = item[:price]
              variant.notes = item[:notes] if variant.respond_to?(:notes)
              update_variant_hook(variant, item)
              variant.build_options(variant_options(item))

    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

    Complex method Spree::Inventory::Providers::DefaultVariantProvider#create_product (25.5)
    Open

            def create_product(identifier)
              metadata = find_metadata(identifier)
              raise ImportError, t('metadata_not_found', default: I18n.t('actions.spree.inventory.providers.default_variant_provider.metadata_not_found')) if metadata.blank?
    
              create_stock_location

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Complex method Spree::Inventory::Providers::DefaultVariantProvider#update_variant (22.0)
    Open

            def update_variant(variant, item)
              variant.price = variant.cost_price = item[:price]
              variant.notes = item[:notes] if variant.respond_to?(:notes)
              update_variant_hook(variant, item)
              variant.build_options(variant_options(item))

    Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

    You can read more about ABC metrics or the flog tool

    Avoid using update_all because it skips validations.
    Open

                     .update_all(upload_id: upload_id, upload_index: upload_index)

    This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

    Example:

    # bad
    Article.first.decrement!(:view_count)
    DiscussionBoard.decrement_counter(:post_count, 5)
    Article.first.increment!(:view_count)
    DiscussionBoard.increment_counter(:post_count, 5)
    person.toggle :active
    product.touch
    Billing.update_all("category = 'authorized', author = 'David'")
    user.update_attribute(:website, 'example.com')
    user.update_columns(last_request_at: Time.current)
    Post.update_counters 5, comment_count: -1, action_count: 1
    
    # good
    user.update(website: 'example.com')
    FileUtils.touch('file')

    Line is too long. [169/150]
    Open

              raise ImportError, t('metadata_not_found', default: I18n.t('actions.spree.inventory.providers.default_variant_provider.metadata_not_found')) if metadata.blank?

    This cop checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/Tab cop.

    Pass &:to_i as an argument to cast instead of a block.
    Open

              item_json[:quantity] = cast(item_json[:quantity]) { |v| v.to_i }

    Use symbols as procs when possible.

    Example:

    # bad
    something.map { |s| s.upcase }
    
    # good
    something.map(&:upcase)

    There are no issues that match your filters.

    Category
    Status