Updated

app/builders / event_builder.rb

B
62 lines of codes
7 methods
7.3 complexity/method
9 churn
50.94 complexity
34 duplications
class EventBuilder
  1. EventBuilder assumes too much for instance variable '@contact'
  2. EventBuilder assumes too much for instance variable '@deal'
  3. EventBuilder assumes too much for instance variable '@event'
  4. EventBuilder has no descriptive comment
  5. EventBuilder has at least 6 instance variables
def initialize(user, params) @params = params @user = user @account = user.account end def build
  1. EventBuilder#build has approx 6 statements
@event = @user.account.events.new(@params) set_contact set_deal @event.done = true if @event.kind == 'note' # clean_html_codes() build_files if @params.key?('files') @event end def clean_html_codes @event.content.body = '' if @event.content.present? && @event.kind != 'note'
  1. EventBuilder#clean_html_codes calls '@event.content' 2 times
end def set_contact
  1. Similar code found in 2 nodes Locations: 0 1
if @params.key?(:contact_id) @contact = @account.contacts.find(@params[:contact_id]) @event.contact = @contact end end def set_deal
  1. Similar code found in 2 nodes Locations: 0 1
if @params.key?(:deal_id) @deal = @account.deals.find(@params[:deal_id]) @event.deal = @deal end end def build_files
  1. EventBuilder#build_files has approx 8 statements
result = @params['files'].map.with_index do |file, index| if index.zero? @event = set_attachment(@event, file) next else file_event_params = @params.except(:content, :files) file_event = EventBuilder.new(@user, file_event_params).build file_event = set_attachment(file_event, file) file_event end end @event.files_events = result.compact end def set_attachment(event, file)
  1. EventBuilder#set_attachment has approx 6 statements
attachment = event.build_attachment attachment.file = file
  1. EventBuilder#set_attachment refers to 'attachment' more than self (maybe move it to another class?) Locations: 0 1
attachment.file_type = attachment.check_file_type
  1. EventBuilder#set_attachment refers to 'attachment' more than self (maybe move it to another class?) Locations: 0 1
event rescue StandardError @event.invalid_files = true event end end