taganaka/polipus

View on GitHub
lib/polipus/http.rb

Summary

Maintainability
C
1 day
Test Coverage

Method get_response has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def get_response(url, referer = nil)
      full_path = url.query.nil? ? url.path : "#{url.path}?#{url.query}"

      opts = {}
      opts['User-Agent'] = user_agent if user_agent
Severity: Minor
Found in lib/polipus/http.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

Class HTTP has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class HTTP
    # Maximum number of redirects to follow on each get_response
    REDIRECT_LIMIT = 5
    RESCUABLE_ERRORS = [
      EOFError,
Severity: Minor
Found in lib/polipus/http.rb - About 2 hrs to fix

    Method get has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def get(url, referer = nil)
          limit = redirect_limit
          loc = url
          loop do
            # if redirected to a relative url, merge it with the host of the original
    Severity: Minor
    Found in lib/polipus/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 get_response has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def get_response(url, referer = nil)
          full_path = url.query.nil? ? url.path : "#{url.path}?#{url.query}"
    
          opts = {}
          opts['User-Agent'] = user_agent if user_agent
    Severity: Minor
    Found in lib/polipus/http.rb - About 1 hr to fix

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

          def fetch_pages(url, referer = nil, depth = nil, user_data = nil)
            url = URI(url)
            pages = []
            get(url, referer) do |response, code, location, redirect_to, response_time|
              handle_compression response
      Severity: Minor
      Found in lib/polipus/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 connection has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def connection(url)
            @connections[url.host] ||= {}
            @connections_hits[url.host] ||= {}
      
            if @connections[url.host][url.port]
      Severity: Minor
      Found in lib/polipus/http.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 refresh_connection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def refresh_connection(url)
            if @opts[:logger] && proxy_host && proxy_port
              @opts[:logger].debug { "Request #{url} using proxy: #{proxy_host}:#{proxy_port}" }
            end
      
      
      Severity: Minor
      Found in lib/polipus/http.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

      There are no issues that match your filters.

      Category
      Status