sanger/sequencescape

View on GitHub
lib/record_loader/request_type_loader.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
96%

RecordLoader::RequestTypeLoader#add_library_types refers to 'request_type' more than self (maybe move it to another class?)
Open

      rt_lts = request_type.library_types.pluck(:name)
      library_types.each do |name|
        request_type.library_types << LibraryType.find_or_create_by!(name: name) unless rt_lts.include?(name)
      end

Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

Example

Running Reek on:

class Warehouse
  def sale_price(item)
    (item.price - item.rebate) * @vat
  end
end

would report:

Warehouse#total_price refers to item more than self (FeatureEnvy)

since this:

(item.price - item.rebate)

belongs to the Item class, not the Warehouse.

RecordLoader::RequestTypeLoader#add_acceptable_purposes calls 'request_type.acceptable_purposes' 2 times
Open

      acceptable_purposes = request_type.acceptable_purposes.pluck(:name)
      purposes.each do |name|
        next if acceptable_purposes.include?(name)

        request_type.acceptable_purposes << Purpose.find_by!(name: name)

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.

RecordLoader::RequestTypeLoader#add_library_types calls 'request_type.library_types' 2 times
Open

      rt_lts = request_type.library_types.pluck(:name)
      library_types.each do |name|
        request_type.library_types << LibraryType.find_or_create_by!(name: name) unless rt_lts.include?(name)

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.

RecordLoader::RequestTypeLoader has missing safe method 'create_or_update!'
Open

    def create_or_update!(key, options)

A candidate method for the Missing Safe Method smell are methods whose names end with an exclamation mark.

An exclamation mark in method names means (the explanation below is taken from here ):

The ! in method names that end with ! means, “This method is dangerous”—or, more precisely, this method is the “dangerous” version of an otherwise equivalent method, with the same name minus the !. “Danger” is relative; the ! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name. So, for example, gsub! is the dangerous version of gsub. exit! is the dangerous version of exit. flatten! is the dangerous version of flatten. And so forth.

Such a method is called Missing Safe Method if and only if her non-bang version does not exist and this method is reported as a smell.

Example

Given

class C
  def foo; end
  def foo!; end
  def bar!; end
end

Reek would report bar! as Missing Safe Method smell but not foo!.

Reek reports this smell only in a class context, not in a module context in order to allow perfectly legit code like this:

class Parent
  def foo; end
end

module Dangerous
  def foo!; end
end

class Son < Parent
  include Dangerous
end

class Daughter < Parent
end

In this example, Reek would not report the Missing Safe Method smell for the method foo of the Dangerous module.

RecordLoader::RequestTypeLoader#add_acceptable_purposes doesn't depend on instance state (maybe move it to another class?)
Open

    def add_acceptable_purposes(request_type, purposes)

A Utility Function is any instance method that has no dependency on the state of the instance.

RecordLoader::RequestTypeLoader#add_library_type_validator doesn't depend on instance state (maybe move it to another class?)
Open

    def add_library_type_validator(request_type)

A Utility Function is any instance method that has no dependency on the state of the instance.

RecordLoader::RequestTypeLoader#create_or_update! has the variable name 'e'
Open

    rescue StandardError => e

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

There are no issues that match your filters.

Category
Status