sanger/sequencescape

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage
B
85%

Complex method ApplicationHelper#tabulated_error_messages_for (41.9)
Open

  def tabulated_error_messages_for(*params) # rubocop:todo Metrics/AbcSize
    options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
    objects = params.filter_map { |object_name| instance_variable_get(:"@#{object_name}") }
    count = objects.inject(0) { |sum, object| sum + object.errors.count }
    if count.zero?
Severity: Minor
Found in app/helpers/application_helper.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method ApplicationHelper#render_parsed_json (33.0)
Open

  def render_parsed_json(json) # rubocop:todo Metrics/AbcSize
    case json
    when String
      json
    when Array
Severity: Minor
Found in app/helpers/application_helper.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method ApplicationHelper#dynamic_link_to (32.5)
Open

  def dynamic_link_to(summary_item) # rubocop:todo Metrics/AbcSize
    object = summary_item.object
    if object.instance_of?(Submission)
      link_to("Submission #{object.id}", study_information_submission_path(object.study, object))
    elsif object.instance_of?(Receptacle)
Severity: Minor
Found in app/helpers/application_helper.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method ApplicationHelper#request_count_link (27.6)
Open

  def request_count_link(study, asset, state, request_type) # rubocop:todo Metrics/AbcSize
    matching_requests =
      asset.requests.select { |request| (request.request_type_id == request_type.id) and request.state == state }
    html_options, count = { title: "#{asset.try(:human_barcode) || asset.id} #{state}" }, matching_requests.size

Severity: Minor
Found in app/helpers/application_helper.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

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

    return 'NA' if result.blank?

    if result == 'pass' || result == '1' || result == 'true'
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#tab is controlled by argument 'active'
Open

    active_class = active ? 'active' : ''
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#tab has boolean parameter 'active'
Open

  def tab(name, target: nil, active: false, id: nil)
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#request_link has 6 parameters
Open

  def request_link(object, count, request_type, status = nil, options = {}, link_options = {})
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

ApplicationHelper#request_list_path has 4 parameters
Open

  def request_list_path(object, request_type = nil, status = nil, options = {})
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

ApplicationHelper#tab_pane has boolean parameter 'active'
Open

  def tab_pane(name, id: nil, tab_id: nil, active: false, &block)
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

error_message_header refers to 'object' more than self (maybe move it to another class?)
Open

  count = object.errors.full_messages.count
  model_name = object.class.to_s.tableize.tr('_', ' ').gsub(%r{/.*}, '').singularize
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#render_flashes contains iterators nested 2 deep
Open

      concat(alert(key, id: "message_#{key}") { Array(message).each { |m| concat tag.div(m) } })
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#request_count_link has approx 7 statements
Open

  def request_count_link(study, asset, state, request_type) # rubocop:todo Metrics/AbcSize
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#legacy_javascript_tag has approx 6 statements
Open

  def legacy_javascript_tag
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#request_count_link has 4 parameters
Open

  def request_count_link(study, asset, state, request_type) # rubocop:todo Metrics/AbcSize
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

ApplicationHelper#tabulated_error_messages_for contains iterators nested 2 deep
Open

      error_messages = objects.map { |object| object.errors.full_messages.map { |msg| tag.div(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#tab_pane is controlled by argument 'active'
Open

    active_class = active ? 'active' : ''
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#tab has approx 6 statements
Open

  def tab(name, target: nil, active: false, id: nil)
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#tabulated_error_messages_for has approx 13 statements
Open

  def tabulated_error_messages_for(*params) # rubocop:todo Metrics/AbcSize
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#dynamic_link_to refers to 'object' more than self (maybe move it to another class?)
Open

    if object.instance_of?(Submission)
      link_to("Submission #{object.id}", study_information_submission_path(object.study, object))
    elsif object.instance_of?(Receptacle)
      link_to("#{object.label.capitalize} #{object.name}", receptacle_path(object))
    elsif object.instance_of?(Labware)
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#tab has 4 parameters
Open

  def tab(name, target: nil, active: false, id: nil)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

ApplicationHelper#tab_pane has 4 parameters
Open

  def tab_pane(name, id: nil, tab_id: nil, active: false, &block)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

ApplicationHelper#dynamic_link_to has approx 6 statements
Open

  def dynamic_link_to(summary_item) # rubocop:todo Metrics/AbcSize
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#render_parsed_json has approx 9 statements
Open

  def render_parsed_json(json) # rubocop:todo Metrics/AbcSize
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.)

error_message_header has approx 6 statements
Open

def error_message_header(object)
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.)

Method request_link has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def request_link(object, count, request_type, status = nil, options = {}, link_options = {})
Severity: Minor
Found in app/helpers/application_helper.rb - About 45 mins to fix

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

      def request_list_path(object, request_type = nil, status = nil, options = {})
        options[:state] = status unless status.nil?
        options[:request_type_id] = request_type.id unless request_type.nil?
    
        if object.instance_of?(Receptacle)
    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#dynamic_link_to calls 'object.id' 2 times
    Open

          link_to("Submission #{object.id}", study_information_submission_path(object.study, object))
        elsif object.instance_of?(Receptacle)
          link_to("#{object.label.capitalize} #{object.name}", receptacle_path(object))
        elsif object.instance_of?(Labware)
          link_to("#{object.label.capitalize} #{object.name}", labware_path(object))
    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#request_count_link calls 'link_to count, url_path, html_options' 2 times
    Open

          link_to count, url_path, html_options
        elsif count > 1
          url_path = study_requests_path(study, state: state, request_type_id: request_type.id, asset_id: asset.id)
          link_to count, url_path, html_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#render_parsed_json calls 'json.each' 2 times
    Open

          tag.ul { json.each { |elem| concat tag.li(render_parsed_json(elem)) } }
        when Hash
          tag.dl do
            json.each do |key, value|
    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#tabulated_error_messages_for calls 'object.errors' 2 times
    Open

        count = objects.inject(0) { |sum, object| sum + object.errors.count }
        if count.zero?
          ''
        else
          error_messages = objects.map { |object| object.errors.full_messages.map { |msg| tag.div(msg) } }.join
    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#dynamic_link_to calls 'object.name' 2 times
    Open

          link_to("#{object.label.capitalize} #{object.name}", receptacle_path(object))
        elsif object.instance_of?(Labware)
          link_to("#{object.label.capitalize} #{object.name}", labware_path(object))
    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#dynamic_link_to calls 'object.label' 2 times
    Open

          link_to("#{object.label.capitalize} #{object.name}", receptacle_path(object))
        elsif object.instance_of?(Labware)
          link_to("#{object.label.capitalize} #{object.name}", labware_path(object))
    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#dynamic_link_to calls 'object.label.capitalize' 2 times
    Open

          link_to("#{object.label.capitalize} #{object.name}", receptacle_path(object))
        elsif object.instance_of?(Labware)
          link_to("#{object.label.capitalize} #{object.name}", labware_path(object))
    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#request_count_link calls 'asset.id' 2 times
    Open

        html_options, count = { title: "#{asset.try(:human_barcode) || asset.id} #{state}" }, matching_requests.size
    
        # 0 requests => no link, just '0'
        # 1 request  => request summary page
        # N requests => summary overview
    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#request_count_link calls 'request_type.id' 2 times
    Open

          asset.requests.select { |request| (request.request_type_id == request_type.id) and request.state == state }
        html_options, count = { title: "#{asset.try(:human_barcode) || asset.id} #{state}" }, matching_requests.size
    
        # 0 requests => no link, just '0'
        # 1 request  => request summary page
    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#sorted_requests_for_search performs a nil-check
    Open

        sorted_requests = requests.select { |r| r.pipeline_id.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#request_list_path performs a nil-check
    Open

        options[:state] = status unless status.nil?
        options[:request_type_id] = request_type.id unless request_type.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#sorted_requests_for_search has the variable name 'r'
    Open

        sorted_requests = requests.select { |r| r.pipeline_id.nil? }
    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#render_flashes has the variable name 'm'
    Open

          concat(alert(key, id: "message_#{key}") { Array(message).each { |m| concat tag.div(m) } })
    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