【发布时间】:2018-09-26 14:55:46
【问题描述】:
Metrics/CyclomaticComplexity:notification_path 的圈复杂度太高。 [9/8] 我不明白如何解决这个问题。你能帮帮我吗,有人吗?谢谢
def notification_path
return h.company_trial_activation_index_path if User.current.company.trial_pending?
dot = object.eventable
case object.event.to_sym
when :new_app, :updates_approved, :updates_disapproved, :new_partial_app, :completed_app, :received_lead
h.company_dot_application_path(id: dot.id)
when :bg_check_received, :bg_check_failed, :bg_check_completed
h.company_dot_application_background_checks_path(dot)
when :voe_completed, :voe_corrected, :voe_invalid,
:voe_driving_school_completed, :voe_driving_school_corrected, :voe_driving_school_invalid
h.company_dot_application_applications_requests_path(dot_application_id: dot.id)
when :voe_instructions, :voe_driving_school_instructions
h.company_dot_application_applications_requests_path(dot.id)
when :email_reply, :note, :sms_reply
h.company_dot_application_communications_path(dot.id)
when :follow_up_task, :follow_up_task_on_due_date
h.company_dot_application_follow_up_tasks_path(dot_application_id: dot.id)
when :bulk_actions_background_location, :bulk_actions_background_assign_user, :bulk_actions_background_lead_source
h.home_users_path
else
h.home_users_path
end
end
【问题讨论】:
-
你至少可以跳过最后一个
when -
你的目标是什么?了解为什么会收到此警告?禁用 Rubocop 警告?尽量避免 Rubocop 警告或重构代码以提高可读性?
标签: ruby-on-rails ruby rubocop