app/helpers/search_helper.rb

Summary

Maintainability
A
55 mins
Test Coverage

Assignment Branch Condition size for topic_related_thumbs_from is too high. [26.55/15]
Open

  def topic_related_thumbs_from(images, options = {})
    num_images_to_show = options[:num_images_to_show] ? options[:num_images_to_show] : SystemSetting.number_of_related_images_to_display
    num_images_to_show = [images.length, num_images_to_show].min

    output = '<ul class="images-list">'
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [17/10]
Open

  def topic_related_thumbs_from(images, options = {})
    num_images_to_show = options[:num_images_to_show] ? options[:num_images_to_show] : SystemSetting.number_of_related_images_to_display
    num_images_to_show = [images.length, num_images_to_show].min

    output = '<ul class="images-list">'
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for will_paginate_atom is too high. [15.17/15]
Open

  def will_paginate_atom(collection, xml)
    total_pages = WillPaginate::ViewHelpers.total_pages_for_collection(collection)
    xml.send('atom:link', rel: 'next', href: derive_url_for_rss(page: collection.current_page + 1)) unless collection.current_page.eql?(total_pages)
    xml.send('atom:link', rel: 'prev', href: derive_url_for_rss(page: collection.current_page - 1)) unless collection.current_page.eql?(1)
    xml.send('atom:link', rel: 'last', href: derive_url_for_rss(page: total_pages))
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method topic_related_thumbs_from has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  def topic_related_thumbs_from(images, options = {})
    num_images_to_show = options[:num_images_to_show] ? options[:num_images_to_show] : SystemSetting.number_of_related_images_to_display
    num_images_to_show = [images.length, num_images_to_show].min

    output = '<ul class="images-list">'
Severity: Minor
Found in app/helpers/search_helper.rb - About 55 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

Use the return of the conditional for variable assignment and comparison.
Open

      if options[:link_to]
        output += link_to(img_html_tag, options[:link_to], tabindex: tabindex_attr)
      else
        output += img_html_tag
      end
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

Use @result_sets[zoom_class].size.positive? instead of @result_sets[zoom_class].size > 0.
Open

      next unless @result_sets && @result_sets[zoom_class] && @result_sets[zoom_class].size > 0
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

Example: EnforcedStyle: predicate (default)

# bad

foo == 0
0 > foo
bar.baz > 0

# good

foo.zero?
foo.negative?
bar.baz.positive?

Example: EnforcedStyle: comparison

# bad

foo.zero?
foo.negative?
bar.baz.positive?

# good

foo == 0
0 > foo
bar.baz > 0

Use !empty? instead of size > 0.
Open

      next unless @result_sets && @result_sets[zoom_class] && @result_sets[zoom_class].size > 0
Severity: Minor
Found in app/helpers/search_helper.rb by rubocop

This cop checks for numeric comparisons that can be replaced by a predicate method, such as receiver.length == 0, receiver.length > 0, receiver.length != 0, receiver.length < 1 and receiver.size == 0 that can be replaced by receiver.empty? and !receiver.empty.

Example:

# bad
[1, 2, 3].length == 0
0 == "foobar".length
array.length < 1
{a: 1, b: 2}.length != 0
string.length > 0
hash.size > 0

# good
[1, 2, 3].empty?
"foobar".empty?
array.empty?
!{a: 1, b: 2}.empty?
!string.empty?
!hash.empty?

There are no issues that match your filters.

Category
Status