bblimke/webmock

View on GitHub

Showing 71 of 71 total issues

Method build_request_signature has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def build_request_signature
        method = @webmock_method.to_s.downcase.to_sym

        uri = WebMock::Util::URI.heuristic_parse(self.url)
        uri.path = uri.normalized_path.gsub("[^:]//","/")
Severity: Minor
Found in lib/webmock/http_lib_adapters/curb_adapter.rb - About 1 hr to fix

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

          def to_query(parent, value, options = {})
            options[:notation] ||= :subscript
            case value
            when ::Hash
              value = value.map do |key, val|
    Severity: Minor
    Found in lib/webmock/util/query_mapper.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 to_s has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def to_s(with_response = true)
          request_pattern = @request_stub.request_pattern
          string = "stub_request(:#{request_pattern.method_pattern.to_s},".dup
          string << " \"#{request_pattern.uri_pattern.to_s}\")"
    
    
    Severity: Minor
    Found in lib/webmock/stub_request_snippet.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 values_to_query has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def values_to_query(new_query_values, options = {})
            options[:notation] ||= :subscript
            return if new_query_values.nil?
    
            unless new_query_values.is_a?(Array)
    Severity: Minor
    Found in lib/webmock/util/query_mapper.rb - About 1 hr to fix

      Method convert_json_to_yaml has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def self.convert_json_to_yaml(json) #:nodoc:
              scanner, quoting, marks, times = StringScanner.new(json), false, [], []
              while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
                case char = scanner[1]
                when '"', "'"
      Severity: Minor
      Found in lib/webmock/util/json.rb - About 1 hr to fix

        Method fill_accumulator_for_dot has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def fill_accumulator_for_dot(accumulator, key, value)
                array_value = false
                subkeys = key.split(".")
                current_hash = accumulator
                subkeys[0..-2].each do |subkey|
        Severity: Minor
        Found in lib/webmock/util/query_mapper.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 to_query has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def to_query(parent, value, options = {})
                options[:notation] ||= :subscript
                case value
                when ::Hash
                  value = value.map do |key, val|
        Severity: Minor
        Found in lib/webmock/util/query_mapper.rb - About 1 hr to fix

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

                  def call(request)
                    request.scheme ||= self.scheme
                    request.authority ||= self.authority
          
                    request_signature = build_request_signature(request)
          Severity: Minor
          Found in lib/webmock/http_lib_adapters/async_http_client_adapter.rb - About 1 hr to fix

            Method to_query has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def self.to_query(hash)
                      string = "".dup
                      for key, values in hash
                        if values.nil?
                          string << key.to_s << '&'
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/excon_adapter.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 build_net_http_response has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def build_net_http_response(webmock_response, &block)
                      response = Net::HTTPResponse.send(:response_class, webmock_response.status[0].to_s).new("1.0", webmock_response.status[0].to_s, webmock_response.status[1])
                      body = webmock_response.body
                      body = nil if webmock_response.status[0].to_s == '204'
            
            
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/net_http.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 send_request has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def send_request(head, body)
                    WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
            
                    if stubbed_webmock_response
                      WebMock::CallbackRegistry.invoke_callbacks({lib: :em_http_request}, request_signature, stubbed_webmock_response)
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/em_http_request_adapter.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 rbuf_fill has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                  def rbuf_fill
                    case rv = @io.read_nonblock(BUFSIZE, nil, exception: false)
                    when String
                      return if rv.nil?
                      @rbuf << rv
            Severity: Minor
            Found in lib/webmock/http_lib_adapters/net_http.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 from_webmock has 27 lines of code (exceeds 25 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 1 hr to fix

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

                  def matches?(headers)
                    if empty_headers?(@pattern)
                      empty_headers?(headers)
                    else
                      return false if empty_headers?(headers)
              Severity: Minor
              Found in lib/webmock/request_pattern.rb - About 55 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_webmock_response has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def build_webmock_response(httpclient_response, body = nil)
                    webmock_response = WebMock::Response.new
                    webmock_response.status = [httpclient_response.status, httpclient_response.reason]
              
                    webmock_response.headers = {}.tap do |hash|
              Severity: Minor
              Found in lib/webmock/http_lib_adapters/httpclient_adapter.rb - About 55 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

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

                      str << headers.map do |k,v|
                        v = case v
                          when Regexp then v.inspect
                          when Array then "["+v.map{|w| "'#{w.to_s}'"}.join(", ")+"]"
                          else "'#{v.to_s}'"
              Severity: Minor
              Found in lib/webmock/util/headers.rb and 1 other location - About 50 mins to fix
              lib/webmock/util/headers.rb on lines 26..32

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

              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

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

                      str << headers.map do |k,v|
                        v = case v
                          when Regexp then v.inspect
                          when Array then "["+v.map{|w| "'#{w.to_s}'"}.join(", ")+"]"
                          else "'#{v.to_s}'"
              Severity: Minor
              Found in lib/webmock/util/headers.rb and 1 other location - About 50 mins to fix
              lib/webmock/util/headers.rb on lines 41..47

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

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

                  def matches?(request_signature)
                    content_type = request_signature.headers['Content-Type'] if request_signature.headers
                    content_type = content_type.split(';').first if content_type
                    @method_pattern.matches?(request_signature.method) &&
                      @uri_pattern.matches?(request_signature.uri) &&
              Severity: Minor
              Found in lib/webmock/request_pattern.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 normalize_headers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def self.normalize_headers(headers)
                      return nil unless headers
                      array = headers.map { |name, value|
                        [name.to_s.split(/_|-/).map { |segment| segment.capitalize }.join("-"),
                         case value
              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 build_request_signature has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def build_request_signature
                      method = @webmock_method.to_s.downcase.to_sym
              
                      uri = WebMock::Util::URI.heuristic_parse(self.url)
                      uri.path = uri.normalized_path.gsub("[^:]//","/")
              Severity: Minor
              Found in lib/webmock/http_lib_adapters/curb_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

              Severity
              Category
              Status
              Source
              Language