Updated

app/helpers / admin_helper.rb

D
179 lines of codes
28 methods
5.3 complexity/method
23 churn
149.63 complexity
216 duplications
module AdminHelper
  1. AdminHelper has no descriptive comment
ISO8601_TIMESTAMP = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\z/ def selected_tags @selected_tags ||= Array(params[:tags]).flatten.map(&:to_i).compact.reject(&:zero?) end def mandatory_field content_tag :span, raw(' *'), class: 'mandatory' end def cms_delete_link(model, options = {}) options[:model_name] ||= model.name
  1. AdminHelper#cms_delete_link calls 'options[:model_name]' 2 times Locations: 0 1
options[:url] ||= resource_path(model)
  1. AdminHelper#cms_delete_link calls 'options[:url]' 2 times Locations: 0 1
link_to image_tag('admin/delete.png', :size => "16x16", :alt => "Delete"), options[:url], :data => {
  1. AdminHelper#cms_delete_link calls 'options[:url]' 2 times Locations: 0 1
:confirm => "WARNING: This action cannot be undone.\nAre you sure you want to delete #{h options[:model_name]}?",
  1. AdminHelper#cms_delete_link calls 'options[:model_name]' 2 times Locations: 0 1
:method => :delete } end def admin_petition_facets_for_select(facets, selected)
  1. Similar code found in 3 nodes Locations: 0 1 2
options = admin_petition_facets.map do |facet| [I18n.t(facet, scope: :"petitions.facets.names.admin", quantity: facets[facet]), facet] end options_for_select(options, selected) end def admin_signature_states_for_select(selected) options_for_select(I18n.t(:states, scope: :"admin.signature"), selected) end def admin_archived_petition_facets_for_select(facets, selected)
  1. Similar code found in 3 nodes Locations: 0 1 2
options = admin_archived_petition_facets.map do |facet| [I18n.t(facet, scope: :"petitions.facets.names.admin_archived", quantity: facets[facet]), facet] end options_for_select(options, selected) end def admin_invalidation_facets_for_select(facets, selected)
  1. Similar code found in 3 nodes Locations: 0 1 2
options = admin_invalidation_facets.map do |facet| [I18n.t(facet, scope: :"admin.invalidations.facets.labels", quantity: facets[facet]), facet] end options_for_select(options, selected) end def admin_parliaments_for_select(selected) options_from_collection_for_select(archived_parliaments, :id, :name, selected) end def email_petitioners_with_count_submit_button(form, petition, options = {}) i18n_options = { scope: :admin, count: petition.signature_count,
  1. AdminHelper#email_petitioners_with_count_submit_button calls 'petition.signature_count' 2 times Locations: 0 1
formatted_count: number_with_delimiter(petition.signature_count)
  1. AdminHelper#email_petitioners_with_count_submit_button calls 'petition.signature_count' 2 times Locations: 0 1
} html_options = { name: 'save_and_email', class: 'button', data: { confirm: t(:email_confirm, i18n_options) } }.merge(options) form.submit(t(:email_button, i18n_options), html_options) end def fraudulent_domains?(since: 1.hour.ago, limit: 10)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
!fraudulent_domains(since: since, limit: limit).empty? end def fraudulent_domains(since: 1.hour.ago, limit: 10)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
@fraudulent_domains ||= build_fraudulent_domains(since, limit) end def fraudulent_ips?(since: 1.hour.ago, limit: 10)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
!fraudulent_ips(since: since, limit: limit).empty? end def fraudulent_ips(since: 1.hour.ago, limit: 10)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
@fraudulent_ips ||= build_fraudulent_ips(since, limit) end def trending_domains(since: 1.hour.ago, limit: 10)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
@trending_domains ||= build_trending_domains(since, limit) end def trending_domains?(since: 1.hour.ago, limit: 10)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
!trending_domains(since: since, limit: limit).empty? end def trending_ips(since: 1.hour.ago, limit: 10)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
@trending_ips ||= build_trending_ips(since, limit) end def trending_ips?(since: 1.hour.ago, limit: 10)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
!trending_ips(since: since, limit: limit).empty? end def trending_window? params[:window].present? && params[:window] =~ ISO8601_TIMESTAMP
  1. AdminHelper#trending_window? calls 'params[:window]' 2 times
end def trending_window if trending_window? starts_at = params[:window].in_time_zone ends_at = starts_at.advance(hours: 1) starts_at..ends_at end end def signature_count_interval_menu { "1 second" => "1", "2 seconds" => "2", "5 seconds" => "5", "10 seconds" => "10", "30 seconds" => "30", "1 minute" => "60", "5 minutes" => "300" } end private def admin_petition_facets
  1. AdminHelper#admin_petition_facets doesn't depend on instance state (maybe move it to another class?)
I18n.t(:admin, scope: :"petitions.facets") end def admin_archived_petition_facets
  1. AdminHelper#admin_archived_petition_facets doesn't depend on instance state (maybe move it to another class?)
I18n.t(:admin_archived, scope: :"petitions.facets") end def admin_invalidation_facets
  1. AdminHelper#admin_invalidation_facets doesn't depend on instance state (maybe move it to another class?)
I18n.t(:keys, scope: :"admin.invalidations.facets") end def rate_limit @rate_limit ||= RateLimit.first_or_create! end def build_fraudulent_domains(since, limit)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
  2. AdminHelper#build_fraudulent_domains doesn't depend on instance state (maybe move it to another class?)
Signature.fraudulent_domains(since: since, limit: limit) end def build_fraudulent_ips(since, limit)
  1. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
  2. AdminHelper#build_fraudulent_ips doesn't depend on instance state (maybe move it to another class?)
Signature.fraudulent_ips(since: since, limit: limit) end def build_trending_domains(since, limit)
  1. Similar code found in 2 nodes Locations: 0 1
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
  3. AdminHelper#build_trending_domains has approx 7 statements
all_domains = Signature.trending_domains(since: since, limit: limit + 30) allowed_domains = rate_limit.allowed_domains_list all_domains.inject([]) do |domains, (domain, count)| return domains if domains.size == limit
  1. AdminHelper#build_trending_domains refers to 'domains' more than self (maybe move it to another class?) Locations: 0 1
unless allowed_domains.any?{ |d| d === domain }
  1. AdminHelper#build_trending_domains contains iterators nested 2 deep
  2. AdminHelper#build_trending_domains has the variable name 'd'
domains << [domain, count]
  1. AdminHelper#build_trending_domains refers to 'domains' more than self (maybe move it to another class?) Locations: 0 1
end domains end end def build_trending_ips(since, limit)
  1. Similar code found in 2 nodes Locations: 0 1
  2. AdminHelper takes parameters ['limit', 'since'] to 12 methods Locations: 0 1 2 3 4 5 6 7 8 9 10 11
  3. AdminHelper#build_trending_ips has approx 7 statements
all_ips = Signature.trending_ips(since: since, limit: limit + 30) allowed_ips = rate_limit.allowed_ips_list all_ips.inject([]) do |ips, (ip, count)| return ips if ips.size == limit
  1. AdminHelper#build_trending_ips refers to 'ips' more than self (maybe move it to another class?) Locations: 0 1
unless allowed_ips.any?{ |i| i.include?(ip) }
  1. AdminHelper#build_trending_ips contains iterators nested 2 deep
  2. AdminHelper#build_trending_ips has the variable name 'i'
ips << [ip, count]
  1. AdminHelper#build_trending_ips refers to 'ips' more than self (maybe move it to another class?) Locations: 0 1
end ips end end end