flexirest/flexirest

View on GitHub

Showing 103 of 103 total issues

Avoid deeply nested control flow statements.
Open

              if options[:minimum]
                @errors[validation[:field_name]] << (validation[:options][:message] || "must be at least #{options[:minimum]} characters long") unless value.to_s.length >= options[:minimum]
              end
Severity: Major
Found in lib/flexirest/validation.rb - About 45 mins to fix

    Method each has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def each
          if @subloaders
            if @subloaders.is_a? Array
              @subloaders.each do |loader|
                yield loader
    Severity: Minor
    Found in lib/flexirest/lazy_association_loader.rb - About 45 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

    Avoid deeply nested control flow statements.
    Open

          elsif request_body_type == :json
            @body ||= if params.is_a?(String)
              params
            elsif @post_params.is_a?(String)
              @post_params
    Severity: Major
    Found in lib/flexirest/request.rb - About 45 mins to fix

      Method cache_store= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def cache_store=(value)
              @@cache_store = nil if value.nil? and return
              raise InvalidCacheStoreException.new("Cache store does not implement #read") unless value.respond_to?(:read)
              raise InvalidCacheStoreException.new("Cache store does not implement #write") unless value.respond_to?(:write)
              raise InvalidCacheStoreException.new("Cache store does not implement #fetch") unless value.respond_to?(:fetch)
      Severity: Minor
      Found in lib/flexirest/caching.rb - About 45 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

      Avoid deeply nested control flow statements.
      Open

                  if value.nil?
                    @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
                  else
                    numeric = (true if Float(value) rescue false)
                    if !numeric
      Severity: Major
      Found in lib/flexirest/validation.rb - About 45 mins to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if value.nil?
                      @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
                    else
                      @errors[validation[:field_name]] << (validation[:options][:message] || "must be at least #{options}") unless value.to_f >= options.to_f
        Severity: Minor
        Found in lib/flexirest/validation.rb and 1 other location - About 45 mins to fix
        lib/flexirest/validation.rb on lines 74..77

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if value.nil?
                      @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
                    else
                      @errors[validation[:field_name]] << (validation[:options][:message] || "must be no more than #{options}") unless value.to_f <= options.to_f
        Severity: Minor
        Found in lib/flexirest/validation.rb and 1 other location - About 45 mins to fix
        lib/flexirest/validation.rb on lines 68..71

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

            def delete(path, data, options={})
              set_defaults(options)
              make_safe_request(path) do
                @session.delete(path) do |req|
                  set_per_request_timeout(req, options) if options[:timeout]
        Severity: Major
        Found in lib/flexirest/connection.rb and 3 other locations - About 40 mins to fix
        lib/flexirest/connection.rb on lines 55..62
        lib/flexirest/connection.rb on lines 67..74
        lib/flexirest/connection.rb on lines 79..86

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

            def post(path, data, options={})
              set_defaults(options)
              make_safe_request(path) do
                @session.post(path) do |req|
                  set_per_request_timeout(req, options) if options[:timeout]
        Severity: Major
        Found in lib/flexirest/connection.rb and 3 other locations - About 40 mins to fix
        lib/flexirest/connection.rb on lines 55..62
        lib/flexirest/connection.rb on lines 67..74
        lib/flexirest/connection.rb on lines 91..98

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

            def patch(path, data, options={})
              set_defaults(options)
              make_safe_request(path) do
                @session.patch(path) do |req|
                  set_per_request_timeout(req, options) if options[:timeout]
        Severity: Major
        Found in lib/flexirest/connection.rb and 3 other locations - About 40 mins to fix
        lib/flexirest/connection.rb on lines 55..62
        lib/flexirest/connection.rb on lines 79..86
        lib/flexirest/connection.rb on lines 91..98

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

            def put(path, data, options={})
              set_defaults(options)
              make_safe_request(path) do
                @session.put(path) do |req|
                  set_per_request_timeout(req, options) if options[:timeout]
        Severity: Major
        Found in lib/flexirest/connection.rb and 3 other locations - About 40 mins to fix
        lib/flexirest/connection.rb on lines 67..74
        lib/flexirest/connection.rb on lines 79..86
        lib/flexirest/connection.rb on lines 91..98

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Consider simplifying this complex logical expression.
        Open

              return v if v.is_a?(Date) || v.is_a?(DateTime) ||
                          v.kind_of?(NilClass) || v.kind_of?(TrueClass) || v.kind_of?(FalseClass) || v.kind_of?(Numeric)
        Severity: Major
        Found in lib/flexirest/attribute_parsing.rb - About 40 mins 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/flexirest/request.rb - About 40 mins to fix

            Method warn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.warn(message)
                  if defined?(Rails) && Rails.logger.present?
                    Rails.logger.warn(message)
                  elsif @logfile
                    if @logfile.is_a?(String)
            Severity: Minor
            Found in lib/flexirest/logger.rb - About 35 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 read_cached_response has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def read_cached_response(request, quiet)
                    if cache_store && perform_caching && request.method[:method] == :get
                      key = "#{request.class_name}:#{request.original_url}"
                      Flexirest::Logger.debug "  \033[1;4;32m#{Flexirest.name}\033[0m #{key} - Trying to read from cache" unless quiet
                      value = cache_store.read(key)
            Severity: Minor
            Found in lib/flexirest/caching.rb - About 35 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 sign_request has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def sign_request(request, api_auth)
                  return if api_auth[:api_auth_access_id].nil? || api_auth[:api_auth_secret_key].nil?
                  ApiAuth.sign!(
                    request,
                    api_auth[:api_auth_access_id],
            Severity: Minor
            Found in lib/flexirest/connection.rb - About 35 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 error has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.error(message)
                  if defined?(Rails) && Rails.logger.present?
                    Rails.logger.error(message)
                  elsif @logfile
                    if @logfile.is_a?(String)
            Severity: Minor
            Found in lib/flexirest/logger.rb - About 35 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 append_parameter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def self.append_parameter(fp, key, value)
                    if value.is_a?(Array)
                      value.each do |i|
                        append_parameter(fp, "#{key}[]", i)
                      end
            Severity: Minor
            Found in lib/flexirest/multipart.rb - About 35 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 parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def parse(body, object)
                    # Save resource class for building lazy association loaders
                    save_resource_class(object)
            
                    # According to the spec:
            Severity: Minor
            Found in lib/flexirest/json_api_proxy.rb - About 35 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 info has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.info(message)
                  if defined?(Rails) && Rails.logger.present?
                    Rails.logger.info(message)
                  elsif @logfile
                    if @logfile.is_a?(String)
            Severity: Minor
            Found in lib/flexirest/logger.rb - About 35 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

            Severity
            Category
            Status
            Source
            Language