ikuseiGmbH/smart-village-app-cms

View on GitHub
app/helpers/application_helper.rb

Summary

Maintainability
A
25 mins
Test Coverage

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

  def visibility_switch(item, item_class)
    input_switch = check_box_tag(
      "visible-#{item.id}",
      item.visible ? 'freigegeben' : 'gesperrt',
      item.visible,
Severity: Minor
Found in app/helpers/application_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.

ApplicationHelper#visibility_location_href calls 'item.visible' 2 times
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"

    "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}';"
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#editor? calls '@current_user.permission' 3 times
Wontfix

    return false if @current_user.permission.blank?
    return true if @current_user.permission == "admin"
    return true if @current_user.permission == "editor"
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 has no descriptive comment
Open

module ApplicationHelper
Severity: Minor
Found in app/helpers/application_helper.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ApplicationHelper#extended_user? calls '@current_user.permission' 2 times
Open

    return false if @current_user.permission.blank?
    return true if @current_user.permission == "extended_user"
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#visibility_switch calls 'item.id' 2 times
Wontfix

      "visible-#{item.id}",
      item.visible ? 'freigegeben' : 'gesperrt',
      item.visible,
      class: "custom-control-input"
    )
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#visible_in_role? calls '@current_user.roles' 2 times
Open

    return false if @current_user.roles.blank?

    @current_user.roles.fetch(role_name, false) == true
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#visibility_location_href calls 'item.id' 2 times
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"

    "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}';"
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#visibility_switch calls 'item.visible' 2 times
Wontfix

      item.visible ? 'freigegeben' : 'gesperrt',
      item.visible,
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.

Method visibility_location_href has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def visibility_location_href(item, item_class)
    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"

    "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}';"
  end
Severity: Minor
Found in app/helpers/application_helper.rb - About 25 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#to_local_date_time doesn't depend on instance state (maybe move it to another class?)
Open

  def to_local_date_time(date_time)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

ApplicationHelper#to_unix_timestamp doesn't depend on instance state (maybe move it to another class?)
Open

  def to_unix_timestamp(date)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

ApplicationHelper#visibility_location_href doesn't depend on instance state (maybe move it to another class?)
Open

  def visibility_location_href(item, item_class)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

ApplicationHelper#to_local_date doesn't depend on instance state (maybe move it to another class?)
Open

  def to_local_date(date)
Severity: Minor
Found in app/helpers/application_helper.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Line is too long. [132/100]
Open

    return false if @current_user.permission == "extended_user" && item.data_provider.id.to_i != @current_user.data_provider_id.to_i
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Missing magic comment # frozen_string_literal: true.
Open

module ApplicationHelper
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop is designed to help upgrade to after Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default after Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: always (default)

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Use 2 (not 0) spaces for rails indentation.
Open

  def visibility_location_href(item, item_class)
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks for indentation that doesn't use the specified number of spaces.

See also the IndentationConsistency cop which is the companion to this one.

Example:

# bad
class A
 def test
  puts 'hello'
 end
end

# good
class A
  def test
    puts 'hello'
  end
end

Example: IgnoredPatterns: ['^\s*module']

# bad
module A
class B
  def test
  puts 'hello'
  end
end
end

# good
module A
class B
  def test
    puts 'hello'
  end
end
end

Prefer double-quoted strings inside interpolations.
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Line is too long. [161/100]
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Prefer double-quoted strings inside interpolations.
Open

    "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}';"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Prefer double-quoted strings inside interpolations.
Open

    "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}';"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Avoid the use of the case equality operator ===.
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks for uses of the case equality operator(===).

Example:

# bad
Array === something
(1..100) === 7
/something/ === some_string

# good
something.is_a?(Array)
(1..100).include?(7)
some_string =~ /something/

Prefer double-quoted strings inside interpolations.
Open

    return "location.href = '/visibility/#{item_class}/#{item.id}/#{item.visible ? 'false' : 'true'}/#{item.survey_poll_id}';" if item_class === "Survey_Comment"
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Missing top-level module documentation comment.
Open

module ApplicationHelper
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      item.visible ? 'freigegeben' : 'gesperrt',
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      item.visible ? 'freigegeben' : 'gesperrt',
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

There are no issues that match your filters.

Category
Status