Updated

app/controllers / application_controller.rb

B
104 lines of codes
20 methods
3.5 complexity/method
19 churn
70.06 complexity
0 duplications
class ApplicationController < ActionController::Base
  1. ApplicationController has no descriptive comment
  2. ApplicationController has at least 20 methods
protect_from_forgery with: :exception before_action :reload_site before_action :reload_parliament before_action :service_unavailable, unless: :site_enabled? before_action :authenticate, if: :site_protected? before_action :redirect_to_url_without_format, if: :unknown_format? before_action :set_seen_cookie_message, if: :show_cookie_message? helper_method :show_cookie_message?, :public_petition_facets hide_action :admin_request? def admin_request? false end protected def authenticate authenticate_or_request_with_http_basic(Site.name) do |username, password| Site.authenticate(username, password) end end def csv_request? request.format.symbol == :csv end def json_request? request.format.symbol == :json end def unknown_format? request.format.nil?
  1. ApplicationController#unknown_format? performs a nil-check
end def url_without_format URI.parse(request.original_url).tap do |uri| uri.path = File.join(File.dirname(request.path), File.basename(request.path, '.*'))
  1. ApplicationController#url_without_format calls 'request.path' 2 times
end.to_s rescue URI::InvalidURIError => e
  1. ApplicationController#url_without_format has the variable name 'e'
home_url end def redirect_to_url_without_format redirect_to url_without_format end def reload_site
  1. ApplicationController#reload_site doesn't depend on instance state (maybe move it to another class?)
Site.reload end def reload_parliament
  1. ApplicationController#reload_parliament doesn't depend on instance state (maybe move it to another class?)
Parliament.reload end def service_unavailable raise Site::ServiceUnavailable, "Sorry, the website is temporarily unavailable" end def site_enabled?
  1. ApplicationController#site_enabled? doesn't depend on instance state (maybe move it to another class?)
Site.enabled? end def site_protected? Site.protected? unless request.local? end def parliament_dissolved?
  1. ApplicationController#parliament_dissolved? doesn't depend on instance state (maybe move it to another class?)
Parliament.dissolved? end def redirect_to_home_page redirect_to home_url end def set_seen_cookie_message cookies[:seen_cookie_message] = { value: 'yes', expires: 1.year.from_now, httponly: true } end def set_cors_headers headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Allow-Methods'] = 'GET' headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept' end def show_cookie_message? @show_cookie_message ||= cookies[:seen_cookie_message] != 'yes' end def public_petition_facets
  1. ApplicationController#public_petition_facets doesn't depend on instance state (maybe move it to another class?)
I18n.t('public', scope: :"petitions.facets") end def do_not_cache response.headers['Cache-Control'] = 'no-store, no-cache' end def current_time
  1. ApplicationController#current_time doesn't depend on instance state (maybe move it to another class?)
Time.current.getutc.iso8601 end end