sanger/sequencescape

View on GitHub
app/middleware/api/endpoint_handler.rb

Summary

Maintainability
A
1 hr
Test Coverage
C
72%

Complex method Api::EndpointHandler::file_addition (112.2)
Open

      def file_addition(action, http_method) # rubocop:todo Metrics/AbcSize
        send(
          http_method,
          %r{/([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?:/([^/]+(?:/[^/]+)*))?},
          file_attached: true
Severity: Minor
Found in app/middleware/api/endpoint_handler.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

Complex method Api::EndpointHandler::file_model_addition (73.4)
Open

      def file_model_addition(action, http_method) # rubocop:todo Metrics/AbcSize
        send(http_method, %r{/([^\d/][^/]+(?:/[^/]+){0,2})}, file_attached: true) do
          if request.acceptable_media_types.prioritize(registered_mimetypes).present?
            raise Core::Service::ContentFiltering::InvalidRequestedContentType
          end
Severity: Minor
Found in app/middleware/api/endpoint_handler.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

Complex method Api::EndpointHandler::file_action (66.9)
Open

      def file_action(action, http_method) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
        send(
          http_method,
          %r{/([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?:/([^/]+(?:/[^/]+)*))?},
          file_requested: true
Severity: Minor
Found in app/middleware/api/endpoint_handler.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

Complex method Api::EndpointHandler::instance_action (56.7)
Open

      def instance_action(action, http_method) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
        send(
          http_method,
          %r{/([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?:/([^/]+(?:/[^/]+)*))?},
          file_attached: false,
Severity: Minor
Found in app/middleware/api/endpoint_handler.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

Method file_addition has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def file_addition(action, http_method) # rubocop:todo Metrics/AbcSize
        send(
          http_method,
          %r{/([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?:/([^/]+(?:/[^/]+)*))?},
          file_attached: true
Severity: Minor
Found in app/middleware/api/endpoint_handler.rb - About 1 hr to fix

    Api::EndpointHandler#file_action contains iterators nested 2 deep
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Nested Iterator occurs when a block contains another block.

    Example

    Given

    class Duck
      class << self
        def duck_names
          %i!tick trick track!.each do |surname|
            %i!duck!.each do |last_name|
              puts "full name is #{surname} #{last_name}"
            end
          end
        end
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

    Api::EndpointHandler#instance_action contains iterators nested 2 deep
    Open

                  request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Nested Iterator occurs when a block contains another block.

    Example

    Given

    class Duck
      class << self
        def duck_names
          %i!tick trick track!.each do |surname|
            %i!duck!.each do |last_name|
              puts "full name is #{surname} #{last_name}"
            end
          end
        end
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

    Api::EndpointHandler#file_action has approx 10 statements
    Open

          def file_action(action, http_method) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#return_file has approx 10 statements
    Open

        def return_file(http_request, action, parts) # rubocop:todo Metrics/AbcSize
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#handle_request has approx 12 statements
    Open

        def handle_request(handler, http_request, action, parts) # rubocop:todo Metrics/AbcSize
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#determine_model_from_parts refers to 'parts' more than self (maybe move it to another class?)
    Open

          parts
            .length
            .downto(1) do |n|
              model_name, remainder = parts.slice(0, n), parts.slice(n, parts.length)
              model_constant = model_name.join('/').classify
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    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.

    Api::EndpointHandler#file_addition contains iterators nested 2 deep
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Nested Iterator occurs when a block contains another block.

    Example

    Given

    class Duck
      class << self
        def duck_names
          %i!tick trick track!.each do |surname|
            %i!duck!.each do |last_name|
              puts "full name is #{surname} #{last_name}"
            end
          end
        end
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

    Api::EndpointHandler has at least 16 methods
    Open

      class EndpointHandler < ::Core::Service
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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)

    Api::EndpointHandler#file_model_addition has approx 15 statements
    Open

          def file_model_addition(action, http_method) # rubocop:todo Metrics/AbcSize
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#model_action contains iterators nested 3 deep
    Open

                    request.io = lookup_for_class(model) { |_| nil }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Nested Iterator occurs when a block contains another block.

    Example

    Given

    class Duck
      class << self
        def duck_names
          %i!tick trick track!.each do |surname|
            %i!duck!.each do |last_name|
              puts "full name is #{surname} #{last_name}"
            end
          end
        end
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

    Api::EndpointHandler#handle_request has 4 parameters
    Open

        def handle_request(handler, http_request, action, parts) # rubocop:todo Metrics/AbcSize
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Long Parameter List occurs when a method has a lot of parameters.

    Example

    Given

    class Dummy
      def long_list(foo,bar,baz,fling,flung)
        puts foo,bar,baz,fling,flung
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [2]:Dummy#long_list has 5 parameters (LongParameterList)

    A common solution to this problem would be the introduction of parameter objects.

    Api::EndpointHandler#file_model_addition contains iterators nested 3 deep
    Open

                      request.io = lookup_for_class(model) { |_| nil }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A Nested Iterator occurs when a block contains another block.

    Example

    Given

    class Duck
      class << self
        def duck_names
          %i!tick trick track!.each do |surname|
            %i!duck!.each do |last_name|
              puts "full name is #{surname} #{last_name}"
            end
          end
        end
      end
    end

    Reek would report the following warning:

    test.rb -- 1 warning:
      [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

    Api::EndpointHandler#determine_model_from_parts has approx 8 statements
    Open

        def determine_model_from_parts(*parts) # rubocop:todo Metrics/MethodLength
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#model_action has approx 7 statements
    Open

          def model_action(action, http_method)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#file_addition has approx 18 statements
    Open

          def file_addition(action, http_method) # rubocop:todo Metrics/AbcSize
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Api::EndpointHandler#instance_action has approx 8 statements
    Open

          def instance_action(action, http_method) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A method with Too Many Statements is any method that has a large number of lines.

    Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

    So the following method would score +6 in Reek's statement-counting algorithm:

    def parse(arg, argv, &error)
      if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
        return nil, block, nil                                         # +1
      end
      opt = (val = parse_arg(val, &error))[1]                          # +2
      val = conv_arg(*val)                                             # +3
      if opt and !arg
        argv.shift                                                     # +4
      else
        val[0] = nil                                                   # +5
      end
      val                                                              # +6
    end

    (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

    Complex method Api::EndpointHandler::model_action (24.3)
    Open

          def model_action(action, http_method)
            send(http_method, %r{/([^\d/][^/]+(?:/[^/]+){0,2})}, file_attached: false, file_requested: false) do
              report('model') do
                determine_model_from_parts(*params[:captures].join.split('/')) do |model, parts|
                  handle_request(:model, request, action, parts) do |request|
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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

    Complex method Api::EndpointHandler#handle_request (23.2)
    Open

        def handle_request(handler, http_request, action, parts) # rubocop:todo Metrics/AbcSize
          endpoint_lookup, io_lookup =
            case handler
            when :instance
              %i[endpoint_for_object lookup_for_object]
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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

    Api::EndpointHandler#report calls 'request.fullpath' 2 times
    Open

          Rails.logger.info("API[start]: #{handler}: #{request.fullpath}")
          yield
        ensure
          Rails.logger.info("API[handled]: #{handler}: #{request.fullpath} in #{Time.zone.now - start}s")
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#determine_model_from_parts calls 'parts; .length' 2 times
    Open

          parts
            .length
            .downto(1) do |n|
              model_name, remainder = parts.slice(0, n), parts.slice(n, parts.length)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#instance_action calls 'uuid.resource.class' 2 times
    Open

                  request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                  request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#report calls 'Rails.logger' 2 times
    Open

          Rails.logger.info("API[start]: #{handler}: #{request.fullpath}")
          yield
        ensure
          Rails.logger.info("API[handled]: #{handler}: #{request.fullpath} in #{Time.zone.now - start}s")
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_addition calls 'request.body' 2 times
    Open

                  file.write(request.body.read)
    
                  # Be kind...
                  file.rewind
                  request.body.rewind
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_addition calls 'uuid.resource' 2 times
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                    request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#report calls 'Time.zone' 2 times
    Open

          start = Time.zone.now
          Rails.logger.info("API[start]: #{handler}: #{request.fullpath}")
          yield
        ensure
          Rails.logger.info("API[handled]: #{handler}: #{request.fullpath} in #{Time.zone.now - start}s")
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#report calls 'Time.zone.now' 2 times
    Open

          start = Time.zone.now
          Rails.logger.info("API[start]: #{handler}: #{request.fullpath}")
          yield
        ensure
          Rails.logger.info("API[handled]: #{handler}: #{request.fullpath} in #{Time.zone.now - start}s")
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#instance_action calls 'uuid.resource' 2 times
    Open

                  request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                  request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_action calls 'params[:captures]' 2 times
    Open

                uuid_in_url, parts = params[:captures][0], params[:captures][1].try(:split, '/') || []
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_action calls 'uuid.resource' 3 times
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                    request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
                  end
                uuid.resource.__send__(file_through) { |file| send_file file.path, filename: file.filename }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_addition calls 'params[:captures]' 2 times
    Open

                  uuid_in_url, parts = params[:captures][0], params[:captures][1].try(:split, '/') || []
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_addition calls 'uuid.resource.class' 2 times
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                    request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#handle_request calls 'Rails.logger' 2 times
    Open

              Rails.logger.info("API[payload]: #{@json}")
              yield(request)
            end
    
          endpoint = send(endpoint_lookup, request.target)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_model_addition calls 'request.body' 2 times
    Open

                  file.write(request.body.read)
    
                  # Be kind...
                  file.rewind
                  request.body.rewind
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#instance_action calls 'params[:captures]' 2 times
    Open

                uuid_in_url, parts = params[:captures][0], params[:captures][1].try(:split, '/') || []
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler assumes too much for instance variable '@json'
    Open

      class EndpointHandler < ::Core::Service
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    Classes should not assume that instance variables are set or present outside of the current class definition.

    Good:

    class Foo
      def initialize
        @bar = :foo
      end
    
      def foo?
        @bar == :foo
      end
    end

    Good as well:

    class Foo
      def foo?
        bar == :foo
      end
    
      def bar
        @bar ||= :foo
      end
    end

    Bad:

    class Foo
      def go_foo!
        @bar = :foo
      end
    
      def foo?
        @bar == :foo
      end
    end

    Example

    Running Reek on:

    class Dummy
      def test
        @ivar
      end
    end

    would report:

    [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

    Note that this example would trigger this smell warning as well:

    class Parent
      def initialize(omg)
        @omg = omg
      end
    end
    
    class Child < Parent
      def foo
        @omg
      end
    end

    The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

    class Parent
      attr_reader :omg
    
      def initialize(omg)
        @omg = omg
      end
    end
    
    class Child < Parent
      def foo
        omg
      end
    end

    Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

    If you don't want to expose those methods as public API just make them private like this:

    class Parent
      def initialize(omg)
        @omg = omg
      end
    
      private
      attr_reader :omg
    end
    
    class Child < Parent
      def foo
        omg
      end
    end

    Current Support in Reek

    An instance variable must:

    • be set in the constructor
    • or be accessed through a method with lazy initialization / memoization.

    If not, Instance Variable Assumption will be reported.

    Api::EndpointHandler#file_action calls 'uuid.resource.class' 2 times
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
                    request.target = request.io.eager_loading_for(uuid.resource.class).include_uuid.find(uuid.resource_id)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler assumes too much for instance variable '@registered_mimetypes'
    Open

      class EndpointHandler < ::Core::Service
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    Classes should not assume that instance variables are set or present outside of the current class definition.

    Good:

    class Foo
      def initialize
        @bar = :foo
      end
    
      def foo?
        @bar == :foo
      end
    end

    Good as well:

    class Foo
      def foo?
        bar == :foo
      end
    
      def bar
        @bar ||= :foo
      end
    end

    Bad:

    class Foo
      def go_foo!
        @bar = :foo
      end
    
      def foo?
        @bar == :foo
      end
    end

    Example

    Running Reek on:

    class Dummy
      def test
        @ivar
      end
    end

    would report:

    [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

    Note that this example would trigger this smell warning as well:

    class Parent
      def initialize(omg)
        @omg = omg
      end
    end
    
    class Child < Parent
      def foo
        @omg
      end
    end

    The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

    class Parent
      attr_reader :omg
    
      def initialize(omg)
        @omg = omg
      end
    end
    
    class Child < Parent
      def foo
        omg
      end
    end

    Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

    If you don't want to expose those methods as public API just make them private like this:

    class Parent
      def initialize(omg)
        @omg = omg
      end
    
      private
      attr_reader :omg
    end
    
    class Child < Parent
      def foo
        omg
      end
    end

    Current Support in Reek

    An instance variable must:

    • be set in the constructor
    • or be accessed through a method with lazy initialization / memoization.

    If not, Instance Variable Assumption will be reported.

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

        def determine_model_from_parts(*parts) # rubocop:todo Metrics/MethodLength
          parts
            .length
            .downto(1) do |n|
              model_name, remainder = parts.slice(0, n), parts.slice(n, parts.length)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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

    Api::EndpointHandler#return_file performs a nil-check
    Open

          raise Core::Service::ContentFiltering::InvalidRequestedContentType if file_through.nil?
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

    Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

    Example

    Given

    class Klass
      def nil_checker(argument)
        if argument.nil?
          puts "argument isn't nil!"
        end
      end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [3]:Klass#nil_checker performs a nil-check. (NilCheck)

    Api::EndpointHandler#lookup_for_class doesn't depend on instance state (maybe move it to another class?)
    Open

        def lookup_for_class(model)
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

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

    Api::EndpointHandler takes parameters ['action', 'http_method'] to 5 methods
    Open

          def file_addition(action, http_method) # rubocop:todo Metrics/AbcSize
            send(
              http_method,
              %r{/([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?:/([^/]+(?:/[^/]+)*))?},
              file_attached: true
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.rb by reek

    In general, a Data Clump occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.

    The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.

    Example

    Given

    class Dummy
      def x(y1,y2); end
      def y(y1,y2); end
      def z(y1,y2); end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)

    A possible way to fix this problem (quoting from Martin Fowler):

    The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.

    Api::EndpointHandler#determine_model_from_parts has the variable name 'n'
    Open

            .downto(1) do |n|
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#lookup_for_class has the variable name 'e'
    Open

        rescue ::Core::Registry::UnregisteredError => e
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_action has the variable name 'e'
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#file_addition has the variable name 'e'
    Open

                    request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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.

    Api::EndpointHandler#instance_action has the variable name 'e'
    Open

                  request.io = lookup_for_class(uuid.resource.class) { |e| raise e }
    Severity: Minor
    Found in app/middleware/api/endpoint_handler.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