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]
- Read upRead up
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?
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?
- Read upRead up
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]')
- Read upRead up
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
- Read upRead up
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?
- Read upRead up
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
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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)
- Read upRead up
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) }
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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]
- Exclude checks
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
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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'}")
- Exclude checks
Line is too long. [160/130] Open
"Product: #{product.inspect}, Taxonomy: #{taxonomy.inspect}, Taxon: #{last_taxon.inspect}, #{last_taxon.errors.full_messages.join(', ')}", :error)
- Exclude checks
Carriage return character detected. Open
class ImportProductsJob < ApplicationJob
queue_as :default
- Exclude checks
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if @product_import.destroy
- Read upRead up
- Exclude checks
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!! "
- Exclude checks