Updated

app/controllers/accounts / products_controller.rb

D
87 lines of codes
11 methods
11.2 complexity/method
27 churn
123.51 complexity
126 duplications
class Accounts::ProductsController < InternalController
  1. Accounts::ProductsController assumes too much for instance variable '@product'
  2. Accounts::ProductsController assumes too much for instance variable '@products'
  3. Accounts::ProductsController has no descriptive comment
include ProductConcern before_action :set_product, only: %i[edit destroy update show edit_custom_attributes update_custom_attributes] def new @product = current_user.account.products.new @product.attachments.build end def create
  1. Accounts::ProductsController#create has approx 6 statements
@product = ProductBuilder.new(current_user, product_params).perform if @product.save respond_to do |format| format.html do redirect_to account_products_path(current_user.account), notice: t('flash_messages.created', model: Product.model_name.human) end format.turbo_stream end else render :new, status: :unprocessable_entity end end def edit; end def update
  1. Similar code found in 3 nodes Locations: 0 1 2
if @product.update(product_params) redirect_to edit_account_product_path(current_user.account, @product), notice: t('flash_messages.updated', model: Product.model_name.human) else render :edit, status: :unprocessable_entity end end def edit_custom_attributes @custom_attribute_definitions = current_user.account.custom_attribute_definitions.product_attribute end def update_custom_attributes @product.custom_attributes[params[:product][:att_key]] = params[:product][:att_value]
  1. Accounts::ProductsController#update_custom_attributes calls 'params[:product]' 2 times
render :edit_custom_attributes, status: :unprocessable_entity unless @product.save end def index
  1. Similar code found in 3 nodes Locations: 0 1 2
@products = if params[:query].present?
  1. Accounts::ProductsController#index calls 'params[:query]' 2 times Locations: 0 1
Product.where( 'name ILIKE :search OR identifier ILIKE :search', search: "%#{params[:query]}%"
  1. Accounts::ProductsController#index calls 'params[:query]' 2 times Locations: 0 1
).order(updated_at: :desc) else Product.all.order(created_at: :desc) end @pagy, @products = pagy(@products) end def destroy
  1. Similar code found in 2 nodes Locations: 0 1
  2. Accounts::ProductsController#destroy has approx 6 statements
@product.destroy respond_to do |format| format.html do redirect_to account_products_path(current_user.account), notice: t('flash_messages.deleted', model: Product.model_name.human) end format.json { head :no_content } end end def select_product_search
  1. Similar code found in 2 nodes Locations: 0 1
  2. Accounts::ProductsController#select_product_search has a flog score of 25
@products = if params[:query].present?
  1. Accounts::ProductsController#select_product_search calls 'params[:query]' 2 times Locations: 0 1
current_user.account.products.where(
  1. Accounts::ProductsController#select_product_search calls 'current_user.account' 2 times Locations: 0 1
  2. Accounts::ProductsController#select_product_search calls 'current_user.account.products' 2 times Locations: 0 1
'name ILIKE :search', search: "%#{params[:query]}%"
  1. Accounts::ProductsController#select_product_search calls 'params[:query]' 2 times Locations: 0 1
).order(updated_at: :desc).limit(5) else current_user.account.products.order(updated_at: :desc).limit(5)
  1. Accounts::ProductsController#select_product_search calls 'current_user.account' 2 times Locations: 0 1
  2. Accounts::ProductsController#select_product_search calls 'current_user.account.products' 2 times Locations: 0 1
end end def show end private def set_product @product = current_user.account.products.find(params[:id]) end end