3scale/porta

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
C
1 day
Test Coverage

Method error_messages_for has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

  def error_messages_for(*params)
    ignore_me = ['Account is invalid', 'Bought cinstances is invalid']
    options = params.extract_options!.symbolize_keys

    objects = if object = options.delete(:object)
Severity: Minor
Found in app/helpers/application_helper.rb - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File application_helper.rb has 270 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ApplicationHelper # rubocop:disable Metrics/ModuleLength

  # this is used just to not load font awesome in tests
  def capybara_webkit?
    Rails.env.test? && defined?(Capybara.current_driver) && Capybara.current_driver == :webkit
Severity: Minor
Found in app/helpers/application_helper.rb - About 2 hrs to fix

    Method error_messages_for has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def error_messages_for(*params)
        ignore_me = ['Account is invalid', 'Bought cinstances is invalid']
        options = params.extract_options!.symbolize_keys
    
        objects = if object = options.delete(:object)
    Severity: Minor
    Found in app/helpers/application_helper.rb - About 1 hr to fix

      ApplicationHelper#active? is controlled by argument 'current'
      Open

          "class=\"active\"" if current == stage
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      ApplicationHelper#next_page refers to 'collection' more than self (maybe move it to another class?)
      Open

          unless collection.current_page == collection.total_entries || collection.total_entries == 0
            "<p style='float:right;'>" + link_to("Next page"[], { :page => collection.current_page.next }.merge(params.reject{|k,v| k=="page"})) + "</p>"
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      ApplicationHelper#error_messages_for contains iterators nested 3 deep
      Open

              error_messages = objects.sum {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) unless ignore_me.include?(msg) } }.join
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      A Nested Iterator occurs when a block contains another block.

      Example

      Given

      class Duck
        class << self
          def duck_names
            %i!tick trick track!.each do |surname|
              %i!duck!.each do |last_name|
                puts "full name is #{surname} #{last_name}"
              end
            end
          end
        end
      end

      Reek would report the following warning:

      test.rb -- 1 warning:
        [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

      ApplicationHelper#search_path has boolean parameter 'atom'
      Open

        def search_path(atom = false)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

      Example

      Given

      class Dummy
        def hit_the_switch(switch = true)
          if switch
            puts 'Hitting the switch'
            # do other things...
          else
            puts 'Not hitting the switch'
            # do other things...
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 3 warnings:
        [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
        [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

      Note that both smells are reported, Boolean Parameter and Control Parameter.

      Getting rid of the smell

      This is highly dependent on your exact architecture, but looking at the example above what you could do is:

      • Move everything in the if branch into a separate method
      • Move everything in the else branch into a separate method
      • Get rid of the hit_the_switch method alltogether
      • Make the decision what method to call in the initial caller of hit_the_switch

      ApplicationHelper#search_path is controlled by argument 'atom'
      Open

          atom ? send("formatted_#{prefix}_posts_path", options.update(:format => :atom)) : send("#{prefix}_posts_path", options)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      ApplicationHelper#active? is controlled by argument 'stage'
      Open

          "class=\"active\"" if current == stage
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      ApplicationHelper#boolean_status_img is controlled by argument 'enabled'
      Open

          if enabled
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Control Parameter is a special case of Control Couple

      Example

      A simple example would be the "quoted" parameter in the following method:

      def write(quoted)
        if quoted
          write_quoted @value
        else
          write_unquoted @value
        end
      end

      Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

      ApplicationHelper#error_messages_for has approx 29 statements
      Open

        def error_messages_for(*params)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      ApplicationHelper#search_path has approx 11 statements
      Open

        def search_path(atom = false)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      A method with Too Many Statements is any method that has a large number of lines.

      Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

      So the following method would score +6 in Reek's statement-counting algorithm:

      def parse(arg, argv, &error)
        if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
          return nil, block, nil                                         # +1
        end
        opt = (val = parse_arg(val, &error))[1]                          # +2
        val = conv_arg(*val)                                             # +3
        if opt and !arg
          argv.shift                                                     # +4
        else
          val[0] = nil                                                   # +5
        end
        val                                                              # +6
      end

      (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

      ApplicationHelper#error_messages_for refers to 'options' more than self (maybe move it to another class?)
      Open

          objects = if object = options.delete(:object)
            [object].flatten
                    else
            params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
                    end
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

      Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

      Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

      Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

      Example

      Running Reek on:

      class Warehouse
        def sale_price(item)
          (item.price - item.rebate) * @vat
        end
      end

      would report:

      Warehouse#total_price refers to item more than self (FeatureEnvy)

      since this:

      (item.price - item.rebate)

      belongs to the Item class, not the Warehouse.

      Method search_path has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def search_path(atom = false)
          options = params[:q].blank? ? {} : {:q => params[:q]}
          prefix =
            if @topic
              options.update :topic_id => @topic, :forum_id => @forum
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method search_posts_title has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def search_posts_title
          returning(params[:q].blank? ? 'Recent Posts'[] : "Searching for"[] + " '#{h params[:q]}'") do |title|
            title << " "+'by {user}'[:by_user,h(@user.display_name)] if @user
            title << " "+'in {forum}'[:in_forum,h(@forum.name)] if @forum
          end
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      ApplicationHelper#error_messages_for calls 'object.errors' 2 times
      Open

          count  = objects.inject(0) {|sum, object| sum + object.errors.count }
          unless count.zero?
            html = {}
            [:id, :class].each do |key|
              if options.include?(key)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#tab calls 'options[:of]' 2 times
      Open

            layout = options[:of] ? "#{options[:of].to_s.pluralize}/" : ''
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#can_be_destroyed? calls 'object.respond_to?(:can_be_destroyed?)' 2 times
      Open

          !object.respond_to?(:can_be_destroyed?) ||
            ( object.respond_to?(:can_be_destroyed?) && object.can_be_destroyed? )
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#error_messages_for calls 'options[:object_name]' 2 times
      Open

            options[:object_name] ||= params.first
      
            I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale|
              header_message = if options.include?(:header_message)
                options[:header_message]
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#favicon_for calls 'account.settings' 3 times
      Open

          return if account.settings.favicon.blank?
          ThreeScale::Warnings.deprecated_method!(:favicon_for)
      
          types = {'ico' => 'x-icon', 'png' => 'png',  'gif' => 'gif'}
          type = account.settings.favicon.split('.').last
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#search_posts_title calls 'params[:q]' 2 times
      Open

          returning(params[:q].blank? ? 'Recent Posts'[] : "Searching for"[] + " '#{h params[:q]}'") do |title|
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#can_be_destroyed? manually dispatches method call
      Open

          !object.respond_to?(:can_be_destroyed?) ||
            ( object.respond_to?(:can_be_destroyed?) && object.can_be_destroyed? )
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

      Example

      class MyManualDispatcher
        attr_reader :foo
      
        def initialize(foo)
          @foo = foo
        end
      
        def call
          foo.bar if foo.respond_to?(:bar)
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

      ApplicationHelper#topic_title_link calls 'forum_topic_path(@forum, topic)' 2 times
      Open

            link_to(h($2.strip), forum_topic_path(@forum, topic), options)
          else
            link_to(h(topic.title), forum_topic_path(@forum, topic), options)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#next_page calls 'collection.total_entries' 2 times
      Open

          unless collection.current_page == collection.total_entries || collection.total_entries == 0
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#capybara_webkit? calls 'Capybara.current_driver' 2 times
      Open

          Rails.env.test? && defined?(Capybara.current_driver) && Capybara.current_driver == :webkit
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#favicon_for calls 'account.settings.favicon' 3 times
      Open

          return if account.settings.favicon.blank?
          ThreeScale::Warnings.deprecated_method!(:favicon_for)
      
          types = {'ico' => 'x-icon', 'png' => 'png',  'gif' => 'gif'}
          type = account.settings.favicon.split('.').last
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#next_page calls 'collection.current_page' 2 times
      Open

          unless collection.current_page == collection.total_entries || collection.total_entries == 0
            "<p style='float:right;'>" + link_to("Next page"[], { :page => collection.current_page.next }.merge(params.reject{|k,v| k=="page"})) + "</p>"
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#search_path calls 'params[:q]' 2 times
      Open

          options = params[:q].blank? ? {} : {:q => params[:q]}
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#topic_title_link calls 'topic.title' 2 times
      Open

          if topic.title =~ /\A\[([^\]]{1,15})\]((\s+)\w+.*)/
            "<span class='flag'>#{$1}</span>" +
            link_to(h($2.strip), forum_topic_path(@forum, topic), options)
          else
            link_to(h(topic.title), forum_topic_path(@forum, topic), options)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      ApplicationHelper#favicon_for performs a nil-check
      Open

          return if account.nil?
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      ApplicationHelper#boolean_status_img has unused parameter 'opts'
      Open

        def boolean_status_img(enabled, opts = {})
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      Unused Parameter refers to methods with parameters that are unused in scope of the method.

      Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

      Example

      Given:

      class Klass
        def unused_parameters(x,y,z)
          puts x,y # but not z
        end
      end

      Reek would emit the following warning:

      [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

      ApplicationHelper#chop has the parameter name 'l'
      Open

        def chop(name, l = 15)
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      An Uncommunicative Parameter Name is a parameter name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      ApplicationHelper#next_page has the variable name 'k'
      Open

            "<p style='float:right;'>" + link_to("Next page"[], { :page => collection.current_page.next }.merge(params.reject{|k,v| k=="page"})) + "</p>"
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      ApplicationHelper#next_page has the variable name 'v'
      Open

            "<p style='float:right;'>" + link_to("Next page"[], { :page => collection.current_page.next }.merge(params.reject{|k,v| k=="page"})) + "</p>"
      Severity: Minor
      Found in app/helpers/application_helper.rb by reek

      An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

      Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

      There are no issues that match your filters.

      Category
      Status