Updated

app/controllers/admin / parliaments_controller.rb

A
61 lines of codes
8 methods
6.2 complexity/method
11 churn
49.87 complexity
0 duplications
class Admin::ParliamentsController < Admin::AdminController
  1. Admin::ParliamentsController assumes too much for instance variable '@parliament'
  2. Admin::ParliamentsController has no descriptive comment
before_action :require_sysadmin before_action :fetch_parliament def show end def update
  1. Admin::ParliamentsController#update has a flog score of 30
  2. Admin::ParliamentsController#update has approx 10 statements
if @parliament.update(parliament_params) if email_creators? @parliament.notify_creators! redirect_to admin_root_url, notice: :creators_emailed elsif schedule_closure? @parliament.schedule_closure! redirect_to admin_root_url, notice: :closure_scheduled elsif archive_petitions? @parliament.start_archiving! redirect_to admin_root_url, notice: :petitions_archiving elsif archive_parliament? @parliament.archive! redirect_to admin_root_url, notice: :parliament_archived else redirect_to admin_root_url, notice: :parliament_updated end else render :show end end private def fetch_parliament @parliament = Parliament.instance end def parliament_params params.require(:parliament).permit( :government, :opening_at, :dissolution_heading, :dissolution_message, :dissolved_heading, :dissolved_message, :dissolution_at, :dissolution_faq_url, :notification_cutoff_at, :registration_closed_at ) end def email_creators? params.key?(:email_creators) && @parliament.dissolution_announced? end def schedule_closure? params.key?(:schedule_closure) && @parliament.dissolution_announced? end def archive_petitions? params.key?(:archive_petitions) && @parliament.can_archive_petitions? end def archive_parliament? params.key?(:archive_parliament) && @parliament.can_archive? end end