ngelx/solidus_import_products

View on GitHub

Showing 66 of 66 total issues

Method extract_product_information has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def extract_product_information
      col.each do |key, value|
        row[value].try :strip!
        if parser.variant_option_field?(key)
          product_information[:variant_options][key] = row[value]
Severity: Minor
Found in app/services/solidus_import_products/process_row.rb - About 1 hr 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 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 extract_column_mappings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def extract_column_mappings
            rows[0].each_with_index do |heading, index|
              break if heading.blank?
              field_name = heading.downcase.gsub(/\A\s*/, '').chomp.gsub(/\s/, '_')
              if field_name.include?('[opt]')
    Severity: Minor
    Found in app/models/solidus_import_products/parser/csv.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 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 convert_to_price has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def convert_to_price(price_str)
          raise SolidusImportProducts::Exception::InvalidPrice unless price_str
          punt = price_str.index('.')
          coma = price_str.index(',')
          if !coma.nil? && !punt.nil?
    Severity: Minor
    Found in app/services/solidus_import_products/process_row.rb - About 35 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 find_and_attach_image_to has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_and_attach_image_to(product_or_variant, filename)
            return if filename.blank?
    
            temp_file = fetch_image(filename)
            return unless temp_file
    Severity: Minor
    Found in lib/solidus_import_products/import_helper.rb - About 35 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 activate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.activate
          Dir.glob(File.join(File.dirname(__FILE__), '../app/**/*_decorator*.rb')) do |c|
            Rails.env.production? ? require(c) : load(c)
          end
    
    
    Severity: Minor
    Found in lib/solidus_import_products/engine.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

    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

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

        def call
          extract_product_information
          product_information_default_values
          logger.log(product_information.to_s, :debug)
    
    
    Severity: Minor
    Found in app/services/solidus_import_products/process_row.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

    Avoid using update_attribute because it skips validations.
    Open

          product.variants.each { |variant| variant.update_attribute(:deleted_at, nil) }

    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_attributes(website: 'example.com')
    FileUtils.touch('file')

    Use snake_case for variable names.
    Open

          def associate_product_with_taxon(product, taxon_hierarchy, putInTop)

    This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

    Example: EnforcedStyle: snake_case (default)

    # bad
    fooBar = 1
    
    # good
    foo_bar = 1

    Example: EnforcedStyle: camelCase

    # bad
    foo_bar = 1
    
    # good
    fooBar = 1

    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]

    Please use Rails.root.join('path', 'to') instead.
    Open

      log_to: File.join(Rails.root, '/log/', "import_products_#{Rails.env}.log"), # Where to log to

    This cop is used to identify usages of file path joining process to use Rails.root.join clause.

    Example:

    # bad Rails.root.join('app/models/goober') File.join(Rails.root, 'app/models/goober') "#{Rails.root}/app/models/goober"

    # good Rails.root.join('app', 'models', 'goober')

    Extra empty line detected at method body end.
    Open

    
          end

    This cops checks if empty lines exist around the bodies of methods.

    Example:

    # good
    
    def foo
      # ...
    end
    
    # bad
    
    def bar
    
      # ...
    
    end

    Line is too long. [139/130]
    Open

              mail(to: @user.email, from: from_address(store), subject: "Spree: Import Products #{error_message.nil? ? 'Success' : 'Failure'}")

    Line is too long. [160/130]
    Open

                  "Product: #{product.inspect}, Taxonomy: #{taxonomy.inspect}, Taxon: #{last_taxon.inspect}, #{last_taxon.errors.full_messages.join(', ')}", :error)

    Carriage return character detected.
    Open

    class ImportProductsJob < ApplicationJob
      queue_as :default
    Severity: Minor
    Found in app/jobs/import_products_job.rb by rubocop

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if @product_import.destroy

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Line is too long. [178/130]
    Open

              raise SolidusImportProducts::Exception::ProductError, "SKU #{product_information[:attributes][:sku]} exists, but #{variant_field}: #{row[variant_column]} not exists!! "
    Severity
    Category
    Status
    Source
    Language