whichdigital/active-rest-client

View on GitHub

Showing 33 of 42 total issues

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

    def valid?
      @errors = Hash.new {|h,k| h[k] = []}
      self.class._validations.each do |validation|
        value = self.send(validation[:field_name])
        validation[:options].each do |type, options|
Severity: Minor
Found in lib/active_rest_client/validation.rb - About 1 day 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

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 write_cached_response has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

                def write_cached_response(request, response, result)
                  return if result.is_a? Symbol
                  return unless perform_caching
                  return unless !result.respond_to?(:_status) || [200, 304].include?(result._status)
                  headers = response.response_headers
          Severity: Minor
          Found in lib/active_rest_client/caching.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 method_missing has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              def method_missing(name, *args)
                if name.to_s[-1,1] == "="
                  name = name.to_s.chop.to_sym
                  @attributes[name] = args.first
                  @dirty_attributes << name
          Severity: Minor
          Found in lib/active_rest_client/base.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_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 initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(name, value, request, options = {})
                @name = name
                class_to_map = request.method[:options][:lazy][name] rescue nil
                @request = class_to_map.nil? ? request : ActiveRestClient::Request.new(class_to_map._mapped_method(:find), class_to_map.new, options)
                @object = nil
          Severity: Minor
          Found in lib/active_rest_client/lazy_association_loader.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 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 valid? has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def valid?
                    @errors = Hash.new {|h,k| h[k] = []}
                    self.class._validations.each do |validation|
                      value = self.send(validation[:field_name])
                      validation[:options].each do |type, options|
              Severity: Minor
              Found in lib/active_rest_client/validation.rb - About 1 hr to fix

                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 inspect has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def inspect
                        inspection = if @attributes.any?
                                       @attributes.collect { |key, value|
                                         "#{key}: #{value_for_inspect(value)}"
                                       }.compact.join(", ")
                  Severity: Minor
                  Found in lib/active_rest_client/base.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

                  Severity
                  Category
                  Status
                  Source
                  Language