sanger/sequencescape

View on GitHub
app/models/pipeline.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
96%

Class Pipeline has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

class Pipeline < ApplicationRecord # rubocop:todo Metrics/ClassLength
  include Uuid::Uuidable
  include Pipeline::BatchValidation
  include SharedBehaviour::Named

Severity: Minor
Found in app/models/pipeline.rb - About 2 hrs to fix

    Pipeline has at least 21 methods
    Open

    class Pipeline < ApplicationRecord # rubocop:todo Metrics/ClassLength
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Too Many Methods is a special case of LargeClass.

    Example

    Given this configuration

    TooManyMethods:
      max_methods: 3

    and this code:

    class TooManyMethods
      def one; end
      def two; end
      def three; end
      def four; end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [1]:TooManyMethods has at least 4 methods (TooManyMethods)

    Pipeline#requests_in_inbox has boolean parameter 'show_held_requests'
    Open

      def requests_in_inbox(show_held_requests = true)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

    Example

    Given

    class Dummy
      def hit_the_switch(switch = true)
        if switch
          puts 'Hitting the switch'
          # do other things...
        else
          puts 'Not hitting the switch'
          # do other things...
        end
      end
    end

    Reek would emit the following warning:

    test.rb -- 3 warnings:
      [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
      [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

    Note that both smells are reported, Boolean Parameter and Control Parameter.

    Getting rid of the smell

    This is highly dependent on your exact architecture, but looking at the example above what you could do is:

    • Move everything in the if branch into a separate method
    • Move everything in the else branch into a separate method
    • Get rid of the hit_the_switch method alltogether
    • Make the decision what method to call in the initial caller of hit_the_switch

    Pipeline#detach_request_from_batch doesn't depend on instance state (maybe move it to another class?)
    Open

      def detach_request_from_batch(_batch, request)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

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

    Pipeline has missing safe method 'robot_verified!'
    Open

      def robot_verified!(batch)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    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.

    Pipeline#input_labware doesn't depend on instance state (maybe move it to another class?)
    Open

      def input_labware(_requests)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

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

    Pipeline#output_labware doesn't depend on instance state (maybe move it to another class?)
    Open

      def output_labware(_requests)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

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

    Pipeline#selected_keys_from doesn't depend on instance state (maybe move it to another class?)
    Open

      def selected_keys_from(browser_options)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

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

    Pipeline#post_finish_batch has unused parameter 'user'
    Open

      def post_finish_batch(batch, user); end
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#post_release_batch has unused parameter 'user'
    Open

      def post_release_batch(batch, user)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#on_start_batch has unused parameter 'batch'
    Open

      def on_start_batch(batch, user)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#on_start_batch has unused parameter 'user'
    Open

      def on_start_batch(batch, user)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#post_finish_batch has unused parameter 'batch'
    Open

      def post_finish_batch(batch, user); end
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#robot_verified! has unused parameter 'batch'
    Open

      def robot_verified!(batch)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#post_release_batch has unused parameter 'batch'
    Open

      def post_release_batch(batch, user)
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    Unused Parameter refers to methods with parameters that are unused in scope of the method.

    Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

    Example

    Given:

    class Klass
      def unused_parameters(x,y,z)
        puts x,y # but not z
      end
    end

    Reek would emit the following warning:

    [2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

    Pipeline#selected_keys_from has the variable name 'v'
    Open

        browser_options.select { |_, v| v == '1' }.keys
    Severity: Minor
    Found in app/models/pipeline.rb by reek

    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