plentz/lol_dba

View on GitHub
lib/lol_dba/index_finding/has_many.rb

Summary

Maintainability
A
0 mins
Test Coverage

Assignment Branch Condition size for find_association_fk is too high. [17.52/15]
Open

    def find_association_fk
      if (source = reflection_options.options[:source])
        association_reflection = through_reflections[source.to_s]
        return nil if association_reflection.options[:polymorphic]
        get_through_foreign_key(association_reflection.klass, reflection_options)

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

LolDba::HasMany has no descriptive comment
Open

  class HasMany < RelationInspector
Severity: Minor
Found in lib/lol_dba/index_finding/has_many.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

Complex method LolDba::HasMany#find_association_fk (22.5)
Open

    def find_association_fk
      if (source = reflection_options.options[:source])
        association_reflection = through_reflections[source.to_s]
        return nil if association_reflection.options[:polymorphic]
        get_through_foreign_key(association_reflection.klass, reflection_options)
Severity: Minor
Found in lib/lol_dba/index_finding/has_many.rb by flog

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

FIXME found
Open

      # FIXME: currently we don't support :through =>
Severity: Minor
Found in lib/lol_dba/index_finding/has_many.rb by fixme

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

      if (association_foreign_key = find_association_fk).present?

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 == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
Open

      elsif belongs_to_reflections = through_reflections[reflection_name.singularize]

This cop checks for assignments in the conditions of if/while/until.

Example:

# bad

if some_var = true
  do_something
end

Example:

# good

if some_var == true
  do_something
end

Missing top-level class documentation comment.
Open

  class HasMany < RelationInspector

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