bblimke/webmock

View on GitHub

Showing 70 of 70 total issues

Avoid deeply nested control flow statements.
Open

                  headers[parts[0]] = [headers[parts[0]]] unless headers[parts[0]].kind_of? Array
Severity: Major
Found in lib/webmock/http_lib_adapters/curb_adapter.rb - About 45 mins to fix

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

          def self.normalize_headers(headers)
            return nil unless headers
    
            headers.each_with_object({}) do |(name, value), new_headers|
              new_headers[normalize_name(name)] =
    Severity: Minor
    Found in lib/webmock/util/headers.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

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

      def self.net_connect_explicit_allowed?(allowed, uri=nil)
        case allowed
        when Array
          allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
        when Regexp
    Severity: Minor
    Found in lib/webmock/webmock.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

    Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

              endpoint,
              protocol = endpoint.protocol,
              scheme = endpoint.scheme,
              authority = endpoint.authority,
              **options
    Severity: Minor
    Found in lib/webmock/http_lib_adapters/async_http_client_adapter.rb - About 35 mins to fix

      Method do_get has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def do_get(req, proxy, conn, stream = false, &block)
      Severity: Minor
      Found in lib/webmock/http_lib_adapters/httpclient_adapter.rb - About 35 mins to fix

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def initialize(library_name, library_version, min_patch_level, max_minor_version = nil, unsupported_versions = [])
        Severity: Minor
        Found in lib/webmock/util/version_checker.rb - About 35 mins to fix

          Method do_request_async has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def do_request_async(method, uri, query, body, extheader)
          Severity: Minor
          Found in lib/webmock/http_lib_adapters/httpclient_adapter.rb - About 35 mins to fix

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

                def read_body(dest = nil, &block)
                  if !(defined?(@__read_body_previously_called).nil?) && @__read_body_previously_called
                    return super
                  end
                  return @body if dest.nil? && block.nil?
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/net_http_response.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 matching_body_array? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def matching_body_array?(query_parameters, pattern, content_type)
                  return false unless query_parameters.is_a?(Array)
                  return false unless query_parameters.length == pattern.length
            
                  query_parameters.each_with_index do |actual, index|
            Severity: Minor
            Found in lib/webmock/request_pattern.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 build_request_signature has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def build_request_signature
                    headers, body = headers_and_body_processed_by_middleware
            
                    method = @req.method
                    uri = @req.uri.clone
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/em_http_request_adapter.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 curb_or_webmock has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def curb_or_webmock
                    request_signature = build_request_signature
                    WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
            
                    if webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/curb_adapter.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 normalize_query_hash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def normalize_query_hash(query_hash, empty_accumulator, options)
                    query_hash.inject(empty_accumulator.dup) do |accumulator, (key, value)|
                      if options[:notation] == :flat_array
                        accumulator << [key, value]
                      else
            Severity: Minor
            Found in lib/webmock/util/query_mapper.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 handle_request has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                      def handle_request(req)
                        request_signature =
                          WebMock::HttpLibAdapters::PatronAdapter.build_request_signature(req)
            
                        WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/patron_adapter.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

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

                def assert_requested(*args, &block)
                  if not args[0].is_a?(WebMock::RequestStub)
                    args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
                  elsif block
                    raise ArgumentError, "assert_requested with a stub object, doesn't accept blocks"
            Severity: Minor
            Found in lib/webmock/api.rb and 1 other location - About 25 mins to fix
            lib/webmock/api.rb on lines 31..37

            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 31.

            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

                def assert_not_requested(*args, &block)
                  if not args[0].is_a?(WebMock::RequestStub)
                    args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
                  elsif block
                    raise ArgumentError, "assert_not_requested with a stub object, doesn't accept blocks"
            Severity: Minor
            Found in lib/webmock/api.rb and 1 other location - About 25 mins to fix
            lib/webmock/api.rb on lines 22..28

            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 31.

            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

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

                def self.request_signature_from_request(net_http, request, body = nil)
                  path = request.path
            
                  if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288
                    path = path.request_uri
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/net_http.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 invoke_callbacks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.invoke_callbacks(options, request_signature, response)
                  return if @@callbacks.empty?
                  CallbackRegistry.callbacks.each do |callback|
                    except = callback[:options][:except]
                    real_only = callback[:options][:real_requests_only]
            Severity: Minor
            Found in lib/webmock/callback_registry.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 from_request_signature has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.from_request_signature(signature)
                  stub = self.new(signature.method.to_sym, signature.uri.to_s)
            
                  if signature.body.to_s != ''
                    body = if signature.url_encoded?
            Severity: Minor
            Found in lib/webmock/request_stub.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 add_query_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def add_query_params(query_params)
                  @query_params = if query_params.is_a?(Hash)
                    query_params
                  elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher) \
                          || query_params.is_a?(WebMock::Matchers::HashExcludingMatcher)
            Severity: Minor
            Found in lib/webmock/request_pattern.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 query_to_values has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def query_to_values(query, options={})
                    return nil if query.nil?
                    query = query.dup.force_encoding('utf-8') if query.respond_to?(:force_encoding)
            
                    options[:notation] ||= :subscript
            Severity: Minor
            Found in lib/webmock/util/query_mapper.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

            Severity
            Category
            Status
            Source
            Language