ikuseiGmbH/smart-village-app-cms

View on GitHub
app/controllers/encounters_supports_controller.rb

Summary

Maintainability
A
55 mins
Test Coverage

Assignment Branch Condition size for verify_user is too high. [32.94/15]
Open

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

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 and https://en.wikipedia.org/wiki/ABC_Software_Metric.

Complex method EncountersSupportsController#verify_user (53.6)
Open

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

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

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

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

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 show is too high. [18.11/15]
Open

  def show
    result = validate_support_id

    if result && result.code == "200" && result.body.present?
      user_data = OpenStruct.new(JSON.parse(result.body))

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 and https://en.wikipedia.org/wiki/ABC_Software_Metric.

Perceived complexity for verify_user is too high. [10/7]
Open

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

  def show
    result = validate_support_id

    if result && result.code == "200" && result.body.present?
      user_data = OpenStruct.new(JSON.parse(result.body))

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.

Cyclomatic complexity for verify_user is too high. [8/6]
Open

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

  def verify_user
    result = validate_support_id
    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")
Severity: Minor
Found in app/controllers/encounters_supports_controller.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

EncountersSupportsController#show has approx 8 statements
Open

  def show

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.)

EncountersSupportsController#validate_support_id has approx 6 statements
Open

    def validate_support_id

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.)

EncountersSupportsController#verify_user has approx 12 statements
Open

  def verify_user

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.)

Complex method EncountersSupportsController#show (26.0)
Open

  def show
    result = validate_support_id

    if result && result.code == "200" && result.body.present?
      user_data = OpenStruct.new(JSON.parse(result.body))

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

EncountersSupportsController tests 'result && result.code == "200" && result.body.present?' at least 3 times
Open

    if result && result.code == "200" && result.body.present?
      user_data = OpenStruct.new(JSON.parse(result.body))

      @user = user_data.to_h.as_json(except: :encounters)
      @encounters = user_data["encounters"]

Repeated Conditional is a special case of Simulated Polymorphism. Basically it means you are checking the same value throughout a single class and take decisions based on this.

Example

Given

class RepeatedConditionals
  attr_accessor :switch

  def repeat_1
    puts "Repeat 1!" if switch
  end

  def repeat_2
    puts "Repeat 2!" if switch
  end

  def repeat_3
    puts "Repeat 3!" if switch
  end
end

Reek would emit the following warning:

test.rb -- 4 warnings:
  [5, 9, 13]:RepeatedConditionals tests switch at least 3 times (RepeatedConditional)

If you get this warning then you are probably not using the right abstraction or even more probable, missing an additional abstraction.

EncountersSupportsController#verify_user calls 'result.body.present?' 2 times
Open

    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")
      result = ApiRequestService.new(uri.to_s, nil, nil, user_id: params[:user_id]).get_request

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.

EncountersSupportsController#verify_user calls 'result.code == "200"' 2 times
Open

    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")
      result = ApiRequestService.new(uri.to_s, nil, nil, user_id: params[:user_id]).get_request

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.

EncountersSupportsController#verify_user calls 'encounters_support_path(params[:id])' 2 times
Open

        redirect_to encounters_support_path(params[:id])
      else
        flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen oder neue Support-ID erstellen."
        redirect_to encounters_support_path(params[:id])

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.

EncountersSupportsController#verify_user calls 'result.code' 2 times
Open

    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")
      result = ApiRequestService.new(uri.to_s, nil, nil, user_id: params[:user_id]).get_request

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.

EncountersSupportsController#verify_user calls 'result.body' 2 times
Open

    if result && result.code == "200" && result.body.present?
      encounter_server = SmartVillageApi.encounter_server_url
      uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")
      result = ApiRequestService.new(uri.to_s, nil, nil, user_id: params[:user_id]).get_request

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.

EncountersSupportsController#verify_user calls 'redirect_to encounters_support_path(params[:id])' 2 times
Open

        redirect_to encounters_support_path(params[:id])
      else
        flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen oder neue Support-ID erstellen."
        redirect_to encounters_support_path(params[:id])

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.

EncountersSupportsController#verify_user calls 'redirect_to encounters_supports_path' 2 times
Open

      redirect_to encounters_supports_path
    end
  rescue StandardError
    flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen."
    redirect_to encounters_supports_path

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.

EncountersSupportsController#show calls 'redirect_to encounters_supports_path' 2 times
Open

      redirect_to encounters_supports_path
    end
  rescue StandardError
    flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen."
    redirect_to encounters_supports_path

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.

EncountersSupportsController#verify_user calls 'params[:id]' 2 times
Open

        redirect_to encounters_support_path(params[:id])
      else
        flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen oder neue Support-ID erstellen."
        redirect_to encounters_support_path(params[:id])

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.

EncountersSupportsController#show calls 'result.body' 2 times
Open

    if result && result.code == "200" && result.body.present?
      user_data = OpenStruct.new(JSON.parse(result.body))

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.

EncountersSupportsController has no descriptive comment
Open

class EncountersSupportsController < ApplicationController

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

Missing magic comment # frozen_string_literal: true.
Open

class EncountersSupportsController < ApplicationController

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

Move redirect_to encounters_support_path(params[:id]) out of the conditional.
Open

        redirect_to encounters_support_path(params[:id])

This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

Example:

# bad
if condition
  do_x
  do_z
else
  do_y
  do_z
end

# good
if condition
  do_x
else
  do_y
end
do_z

# bad
if condition
  do_z
  do_x
else
  do_z
  do_y
end

# good
do_z
if condition
  do_x
else
  do_y
end

# bad
case foo
when 1
  do_x
when 2
  do_x
else
  do_x
end

# good
case foo
when 1
  do_x
  do_y
when 2
  # nothing
else
  do_x
  do_z
end

Move redirect_to encounters_support_path(params[:id]) out of the conditional.
Open

        redirect_to encounters_support_path(params[:id])

This cop checks for identical lines at the beginning or end of each branch of a conditional statement.

Example:

# bad
if condition
  do_x
  do_z
else
  do_y
  do_z
end

# good
if condition
  do_x
else
  do_y
end
do_z

# bad
if condition
  do_z
  do_x
else
  do_z
  do_y
end

# good
do_z
if condition
  do_x
else
  do_y
end

# bad
case foo
when 1
  do_x
when 2
  do_x
else
  do_x
end

# good
case foo
when 1
  do_x
  do_y
when 2
  # nothing
else
  do_x
  do_z
end

Line is too long. [111/100]
Open

        flash[:error] = "Es ist ein Fehler aufgetreten. Bitte erneut versuchen oder neue Support-ID erstellen."

Missing top-level class documentation comment.
Open

class EncountersSupportsController < ApplicationController

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

There are no issues that match your filters.

Category
Status