expertiza/expertiza

View on GitHub
app/models/waitlist.rb

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

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

    def self.remove_from_waitlists(team_id)
        signups = SignedUpTeam.where(team_id: team_id)
        signups.each do |signup|
            signup_topic_id = signup.topic_id
            signup.destroy
Severity: Minor
Found in app/models/waitlist.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

Tab detected.
Open

        end
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Use 2 (not 1) spaces for indentation.
Open

            signup_topic_id = signup.topic_id
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cops 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

Use 2 (not 1) spaces for indentation.
Open

    def self.cancel_all_waitlists(team_id, assignment_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cops 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

Tab detected.
Open

        signups.each do |signup|
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

    end
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

            SignedUpTeam.destroy(waitlisted_topics.map(&:id))
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

        signups = SignedUpTeam.where(team_id: team_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

            first_waitlisted_team = SignedUpTeam.find_by(topic_id: signup_topic_id, is_waitlisted: true)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Favor unless over if for negative conditions.
Open

        if not waitlisted_topics.nil?
            SignedUpTeam.destroy(waitlisted_topics.map(&:id))
        end
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

- both
- prefix
- postfix

Example: EnforcedStyle: both (default)

# enforces `unless` for `prefix` and `postfix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# bad

bar if !foo

# good

bar unless foo

Example: EnforcedStyle: prefix

# enforces `unless` for just `prefix` conditionals

# bad

if !foo
  bar
end

# good

unless foo
  bar
end

# good

bar if !foo

Example: EnforcedStyle: postfix

# enforces `unless` for just `postfix` conditionals

# bad

bar if !foo

# good

bar unless foo

# good

if !foo
  bar
end

Use 2 (not 1) spaces for indentation.
Open

            SignedUpTeam.destroy(waitlisted_topics.map(&:id))
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cops 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

Tab detected.
Open

            signup_topic_id = signup.topic_id
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

        waitlisted_topics = SignUpTopic.find_waitlisted_topics_for_team(assignment_id, team_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

            signup.destroy
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Use ! instead of not.
Open

        if not waitlisted_topics.nil?
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cop checks for uses of the keyword not instead of !.

Example:

# bad - parentheses are required because of op precedence
x = (not something)

# good
x = !something

Use 2 (not 1) spaces for indentation.
Open

        waitlisted_topics = SignUpTopic.find_waitlisted_topics_for_team(assignment_id, team_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cops 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

Tab detected.
Open

            max_choosers = SignUpTopic.find(signup_topic_id).max_choosers
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Use 2 (not 1) spaces for indentation.
Open

        signups = SignedUpTeam.where(team_id: team_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

This cops 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

Tab detected.
Open

            non_waitlisted_users = SignedUpTeam.where(topic_id: signup_topic_id, is_waitlisted: false)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

            SignUpTopic.assign_to_first_waiting_team(first_waitlisted_team) if first_waitlisted_team
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

        end
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Missing top-level class documentation comment.
Open

class Waitlist < ApplicationRecord
Severity: Minor
Found in app/models/waitlist.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

Tab detected.
Open

        if not waitlisted_topics.nil?
Severity: Minor
Found in app/models/waitlist.rb by rubocop

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

        if not waitlisted_topics.nil?
Severity: Minor
Found in app/models/waitlist.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

Tab detected.
Open

    def self.cancel_all_waitlists(team_id, assignment_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

    end
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

    def self.remove_from_waitlists(team_id)
Severity: Minor
Found in app/models/waitlist.rb by rubocop

Tab detected.
Open

            next unless non_waitlisted_users.length < max_choosers
Severity: Minor
Found in app/models/waitlist.rb by rubocop

There are no issues that match your filters.

Category
Status