1require 'uri'
 
2
 
3module ApplicationHelper
 
4  INDEXED_PAGES = [
 
5    %w[pages index],
 
6    %w[pages help],
 
7    %w[pages privacy],
 
8    %w[local_petitions index],
 
 9    %w[local_petitions show],
 
10    %w[petitions index],
 
11    %w[petitions show],
 
12    %w[petitions new],
 
13    %w[archived/petitions index],
 
14    %w[archived/petitions show]
 
15  ]
 
  • Complexity 1 » saikuro
17  def increment(amount = 1)
 
18    @counter ||= 0
 
19    @counter += amount
 
20  end
 
  • Complexity 1 » saikuro
22  def home_page?
 
23    params.values_at(:controller, :action) == %w[pages index]
 
24  end
 
  • Complexity 1 » saikuro
26  def create_petition_page?
 
27    params[:controller] == 'petitions' && params[:action].in?(%w[check create new])
 
28  end
 
  • Complexity 1 » saikuro
30  def petition_page?
 
31    params.values_at(:controller, :action) == %w[petitions show]
 
32  end
 
  • Complexity 1 » saikuro
34  def open_petition_page?
 
35    petition_page? && @petition.open?
 
36  end
 
  • Complexity 1 » saikuro
38  def archived_petition_page?
 
39    params[:controller] == 'archived/petitions' && params[:action] == 'show'
 
40  end
 
  • Complexity 1 » saikuro
42  def back_url
 
43    referer_url || 'javascript:history.back()'
 
44  end
 
  • Complexity 1 » saikuro
46  def noindex_page?
 
47    !params.values_at(:controller, :action).in?(INDEXED_PAGES)
 
48  end
 
  • Complexity 1 » saikuro
50  def original_url
 
51    request.original_url.force_encoding('utf-8')
 
52  end
 
 
54  private
 
  • DuplicateMethodCall - calls 'request.referer' 2 times » reek
  • TooManyStatements - has approx 6 statements » reek
  • UncommunicativeVariableName - has the variable name 'e' » reek
  • UncommunicativeVariableName - has the variable name 'k' » reek
  • Complexity 4 » saikuro
56  def referer_url
 
57    begin
 
58      uri = URI.parse(request.referer)
 
59      %i[scheme host port].all?{ |k| uri.send(k) == request.send(k) } ? request.referer : nil
 
60    rescue URI::InvalidURIError => e
 
61      nil
 
62    end
 
63  end
 
64end