Updated

app/controllers/admin / moderation_delays_controller.rb

A
75 lines of codes
9 methods
5.5 complexity/method
1 churn
49.86 complexity
0 duplications
class Admin::ModerationDelaysController < Admin::AdminController
  1. Admin::ModerationDelaysController assumes too much for instance variable '@moderation_delay'
  2. Admin::ModerationDelaysController has no descriptive comment
before_action :build_moderation_delay def new respond_to do |format| format.html end end def create
  1. Admin::ModerationDelaysController#create has approx 9 statements
if @moderation_delay.valid? save_attributes_to_session enqeue_job if send_email_to_creators? redirect_to admin_petitions_url(state: :overdue_in_moderation), notice: :moderation_delay_sent else respond_to do |format| format.html { render :new, notice: :moderation_delay_preview_sent }
  1. Admin::ModerationDelaysController#create calls 'format.html' 2 times Locations: 0 1
end end else respond_to do |format| format.html { render :new }
  1. Admin::ModerationDelaysController#create calls 'format.html' 2 times Locations: 0 1
end end end private def build_moderation_delay @moderation_delay = ModerationDelay.new(moderation_delay_params) end def moderation_delay_params if params.key?(:moderation_delay) params.require(:moderation_delay).permit(:subject, :body) else session[:moderation_delay] || {} end end def save_attributes_to_session session[:moderation_delay] = @moderation_delay.attributes end def send_email_to_creators? params.key?(:email_creators) end def enqeue_job
  1. Admin::ModerationDelaysController#enqeue_job has approx 9 statements
if send_email_to_creators? job_class = NotifyCreatorsThatModerationIsDelayedJob job_args = [] job_method = :perform_later else job_class = NotifyCreatorThatModerationIsDelayedJob job_args = [feedback_signature] job_method = :perform_now end job_args << @moderation_delay.subject job_args << @moderation_delay.body job_class.public_send(job_method, *job_args) end def feedback_signature FeedbackSignature.new(example_petition) end def example_petition
  1. Admin::ModerationDelaysController#example_petition doesn't depend on instance state (maybe move it to another class?)
Petition.overdue_in_moderation.last end end