whichdigital/active-rest-client

View on GitHub
lib/active_rest_client/request.rb

Summary

Maintainability
F
5 days
Test Coverage

File request.rb has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "cgi"
require "multi_json"
require 'crack'
require 'crack/xml'

Severity: Major
Found in lib/active_rest_client/request.rb - About 1 day to fix

    Method do_request has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_request(etag)
          http_headers = {}
          http_headers["If-None-Match"] = etag if etag
          http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
          headers.each do |key,value|
    Severity: Minor
    Found in lib/active_rest_client/request.rb - About 5 hrs 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

    Method call has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        def call(explicit_parameters=nil)
          @instrumentation_name = "#{class_name}##{@method[:name]}"
          result = nil
          cached = nil
          ActiveSupport::Notifications.instrument("request_call.active_rest_client", :name => @instrumentation_name) do
    Severity: Minor
    Found in lib/active_rest_client/request.rb - About 4 hrs 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

    Class Request has 31 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Request
        attr_accessor :post_params, :get_params, :url, :path, :headers, :method, :object, :body, :forced_url, :original_url
    
        def initialize(method, object, params = {})
          @method                     = method
    Severity: Minor
    Found in lib/active_rest_client/request.rb - About 3 hrs to fix

      Method handle_response has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def handle_response(response, cached = nil)
            @response = response
            status = @response.status || 200
      
            if cached && response.status == 304
      Severity: Minor
      Found in lib/active_rest_client/request.rb - About 3 hrs 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

      Method new_object has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def new_object(attributes, name = nil)
            @method[:options][:has_many] ||= {}
            name = name.to_sym rescue nil
            if @method[:options][:has_many][name]
              overridden_name = name
      Severity: Minor
      Found in lib/active_rest_client/request.rb - About 3 hrs 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

      Method generate_new_object has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def generate_new_object(options={})
            if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
              body = @response.body
            elsif is_json_response?
              body = @response.body.blank? ? {} : MultiJson.load(@response.body)
      Severity: Minor
      Found in lib/active_rest_client/request.rb - About 2 hrs 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

      Method call has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def call(explicit_parameters=nil)
            @instrumentation_name = "#{class_name}##{@method[:name]}"
            result = nil
            cached = nil
            ActiveSupport::Notifications.instrument("request_call.active_rest_client", :name => @instrumentation_name) do
      Severity: Major
      Found in lib/active_rest_client/request.rb - About 2 hrs to fix

        Method do_request has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def do_request(etag)
              http_headers = {}
              http_headers["If-None-Match"] = etag if etag
              http_headers["Accept"] = "application/hal+json, application/json;q=0.5"
              headers.each do |key,value|
        Severity: Major
        Found in lib/active_rest_client/request.rb - About 2 hrs to fix

          Method handle_hal_links_embedded has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle_hal_links_embedded(object, attributes)
                attributes["_links"] = attributes[:_links] if attributes[:_links]
                attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
                if attributes["_links"]
                  attributes["_links"].each do |key, value|
          Severity: Minor
          Found in lib/active_rest_client/request.rb - About 2 hrs 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

          Method handle_response has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def handle_response(response, cached = nil)
                @response = response
                status = @response.status || 200
          
                if cached && response.status == 304
          Severity: Minor
          Found in lib/active_rest_client/request.rb - About 1 hr to fix

            Method new_object has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def new_object(attributes, name = nil)
                  @method[:options][:has_many] ||= {}
                  name = name.to_sym rescue nil
                  if @method[:options][:has_many][name]
                    overridden_name = name
            Severity: Minor
            Found in lib/active_rest_client/request.rb - About 1 hr to fix

              Method hal_response? has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def hal_response?
                    _, content_type = @response.response_headers.detect{|k,v| k.downcase == "content-type"}
                    faked_response = @response.response_headers.detect{|k,v| k.downcase == "x-arc-faked-response"}
                    if content_type && content_type.respond_to?(:each)
                      content_type.each do |ct|
              Severity: Minor
              Found in lib/active_rest_client/request.rb - About 1 hr 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

              Method generate_new_object has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def generate_new_object(options={})
                    if @response.body.is_a?(Array) || @response.body.is_a?(Hash)
                      body = @response.body
                    elsif is_json_response?
                      body = @response.body.blank? ? {} : MultiJson.load(@response.body)
              Severity: Minor
              Found in lib/active_rest_client/request.rb - About 1 hr to fix

                Method handle_hal_links_embedded has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def handle_hal_links_embedded(object, attributes)
                      attributes["_links"] = attributes[:_links] if attributes[:_links]
                      attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
                      if attributes["_links"]
                        attributes["_links"].each do |key, value|
                Severity: Minor
                Found in lib/active_rest_client/request.rb - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                        if @forced_url && @forced_url.present?
                          @url = @forced_url
                        else
                          @url = @method[:url].dup
                          matches = @url.scan(/(:[a-z_-]+)/)
                  Severity: Major
                  Found in lib/active_rest_client/request.rb - About 40 mins to fix

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

                        def prepare_url
                          if @forced_url && @forced_url.present?
                            @url = @forced_url
                          else
                            @url = @method[:url].dup
                    Severity: Minor
                    Found in lib/active_rest_client/request.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

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

                        def prepare_request_body(params = nil)
                          if request_body_type == :form_encoded
                            @body ||= (params || @post_params || {}).to_query
                            headers["Content-Type"] ||= "application/x-www-form-urlencoded"
                          elsif request_body_type == :json
                    Severity: Minor
                    Found in lib/active_rest_client/request.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

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

                        def prepare_params
                          params = @params || @object._attributes rescue {}
                          if params.is_a?(String) || params.is_a?(Fixnum)
                            params = {id:params}
                          end
                    Severity: Minor
                    Found in lib/active_rest_client/request.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

                    There are no issues that match your filters.

                    Category
                    Status