expertiza/expertiza

View on GitHub
app/helpers/conference_helper.rb

Summary

Maintainability
A
25 mins
Test Coverage
F
16%

Assignment Branch Condition size for assign_user_params is too high. [31.69/15]
Open

  def assign_user_params(is_author)
    @user = User.new(user_params)
    # Checks if its a co-author
    if !is_author
      @user.email = params[:user][:name]
Severity: Minor
Found in app/helpers/conference_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

Assignment Branch Condition size for create_author is too high. [24.92/15]
Open

  def create_author
    params[:user][:name] = params[:user][:email] unless !params[:user][:name].nil? && !params[:user][:name].empty?
    is_author = true
    # Assign all user params for creating author using assign_user_params function
    @user = assign_user_params(is_author)
Severity: Minor
Found in app/helpers/conference_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 assign_user_params(is_author)
    @user = User.new(user_params)
    # Checks if its a co-author
    if !is_author
      @user.email = params[:user][:name]
Severity: Minor
Found in app/helpers/conference_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 create_coauthor is too high. [21.93/15]
Open

  def create_coauthor
    check = User.find_by(name: params[:user][:name])
    params[:user][:name] = params[:user][:email] unless check.nil?
    User.skip_callback(:create, :after, :email_welcome)
    is_author = false
Severity: Minor
Found in app/helpers/conference_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. [12/10]
Open

  def create_coauthor
    check = User.find_by(name: params[:user][:name])
    params[:user][:name] = params[:user][:email] unless check.nil?
    User.skip_callback(:create, :after, :email_welcome)
    is_author = false
Severity: Minor
Found in app/helpers/conference_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.

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

  def create_author
    params[:user][:name] = params[:user][:email] unless !params[:user][:name].nil? && !params[:user][:name].empty?
    is_author = true
    # Assign all user params for creating author using assign_user_params function
    @user = assign_user_params(is_author)
Severity: Minor
Found in app/helpers/conference_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.

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

  def is_valid_conference_assignment?
    # if assignment id is present in url the check if it's a valid conference assignment.
    unless params[:assignment_id].nil?
      @assignment = Assignment.find_by_id(params[:assignment_id])
      if !@assignment.nil? && @assignment.is_conference_assignment
Severity: Minor
Found in app/helpers/conference_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

Move @user.timezonepref = User.find(@user.parent_id).timezonepref out of the conditional.
Open

        @user.timezonepref = User.find(@user.parent_id).timezonepref
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

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

Missing top-level module documentation comment.
Open

module ConferenceHelper
Severity: Minor
Found in app/helpers/conference_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

Convert if nested inside else to elsif.
Open

      if is_valid_conference_assignment?
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

Example:

# bad
if condition_a
  action_a
else
  if condition_b
    action_b
  else
    action_c
  end
end

# good
if condition_a
  action_a
elsif condition_b
  action_b
else
  action_c
end

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if @new_user.save
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Do not prefix reader method names with get_.
Open

  def get_redirect_url_link
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

This cop makes sure that accessor methods are named properly.

Example:

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

Rename is_valid_conference_assignment? to valid_conference_assignment?.
Open

  def is_valid_conference_assignment?
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

This cop makes sure that predicates are named properly.

Example:

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if @participant.nil?
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Move @user.timezonepref = User.find(@user.parent_id).timezonepref out of the conditional.
Open

        @user.timezonepref = User.find(@user.parent_id).timezonepref
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

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

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    unless params[:assignment_id].nil?
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if @user.save
Severity: Minor
Found in app/helpers/conference_helper.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

There are no issues that match your filters.

Category
Status