fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/models/classroom_subject.rb

Summary

Maintainability
A
0 mins
Test Coverage

Assignment Branch Condition size for update_alumns_grades is too high. [15.03/15]
Open

  def update_alumns_grades
    self.classroom.alumns.each do |alumn|
      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
      end
Severity: Minor
Found in app/models/classroom_subject.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

ClassroomSubject has no descriptive comment
Open

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

ClassroomSubject#update_alumns_grades calls 'self.subject_id' 2 times
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.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.

ClassroomSubject#update_alumns_grades calls 'alumn.id' 2 times
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.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.

ClassroomSubject#update_alumns_grades calls 'self.classroom_id' 2 times
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.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.

Missing top-level class documentation comment.
Open

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

Extra empty line detected at class body end.
Open


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

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Line is too long. [123/80]
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

Redundant self detected.
Open

        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Redundant self detected.
Open

    self.classroom.alumns.each do |alumn|
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Redundant self detected.
Open

        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Line is too long. [102/80]
Open

        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

Redundant self detected.
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Favor unless over if for negative conditions.
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
        Grade.create(alumn_id: alumn.id, classroom_id: self.classroom_id, subject_id: self.subject_id)
      end
Severity: Minor
Found in app/models/classroom_subject.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

Redundant self detected.
Open

      if !Grade.where(alumn_id: alumn.id).where(classroom_id: self.classroom_id).where(subject_id: self.subject_id).exists?
Severity: Minor
Found in app/models/classroom_subject.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

There are no issues that match your filters.

Category
Status