bblimke/webmock

View on GitHub

Showing 71 of 71 total issues

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

    def build_httpclient_response(webmock_response, stream = false, req_header = nil, &block)
      body = stream ? StringIO.new(webmock_response.body) : webmock_response.body
      response = HTTP::Message.new_response(body, req_header)
      response.header.init_response(webmock_response.status[0])
      response.reason=webmock_response.status[1]
Severity: Minor
Found in lib/webmock/http_lib_adapters/httpclient_adapter.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

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

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

                  def build_request_signature
                    headers, body = build_request, @req.body
            
                    @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
                      headers, body = m.request(self, headers, body)
            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 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 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

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

                def matches?(body, content_type = "")
                  assert_non_multipart_body(content_type)
            
                  if (@pattern).is_a?(Hash)
                    return true if @pattern.empty?
            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 from_webmock has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def from_webmock(request, webmock_response, request_signature = nil)
                    status  = Status.new(webmock_response.status.first)
                    headers = webmock_response.headers || {}
                    uri     = normalize_uri(request_signature && request_signature.uri)
            
            
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/http_rb/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

            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 20..26

            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_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 29..35

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

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

              def self.net_connect_allowed?(uri = nil)
                return !!Config.instance.allow_net_connect if uri.nil?
            
                if uri.is_a?(String)
                  uri = WebMock::Util::URI.normalize_uri(uri)
            Severity: Minor
            Found in lib/webmock/webmock.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

            Severity
            Category
            Status
            Source
            Language