taganaka/polipus

View on GitHub

Showing 28 of 28 total issues

Method takeover has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

    def takeover
      @urls.each do |u|
        add_url(u) { |page| page.user_data.p_seeded = true }
      end
      return if internal_queue.empty?
Severity: Minor
Found in lib/polipus.rb - About 1 day 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

File polipus.rb has 341 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'redis'
require 'redis/connection/hiredis'
require 'redis-queue'
require 'polipus/version'
require 'polipus/http'
Severity: Minor
Found in lib/polipus.rb - About 4 hrs to fix

    Class PolipusCrawler has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class PolipusCrawler
        OPTS = {
          # run 4 threads
          workers: 4,
          # identify self as Polipus/VERSION
    Severity: Minor
    Found in lib/polipus.rb - About 4 hrs to fix

      Method rotate has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

            def rotate(source, dest)
              performed = 0
              loop do
                message = source.pop(true)
                if message
      Severity: Minor
      Found in lib/polipus/queue_overflow/manager.rb - About 3 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

      Method takeover has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def takeover
            @urls.each do |u|
              add_url(u) { |page| page.user_data.p_seeded = true }
            end
            return if internal_queue.empty?
      Severity: Major
      Found in lib/polipus.rb - About 3 hrs to fix

        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

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

              def initialize(uri, user_agent)
                io = Robotex.get_robots_txt(uri, user_agent)
                if !io || io.content_type != 'text/plain' || io.status != %w(200 OK)
                  io = StringIO.new("User-agent: *\nAllow: /\n")
                end
        Severity: Minor
        Found in lib/polipus/robotex.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 initialize has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(job_name = 'polipus', urls = [], options = {})
                @job_name     = job_name
                @options      = OPTS.merge(options)
                @options[:queue_timeout] = 1 if @options[:queue_timeout] <= 0
                @logger       = @options[:logger]  ||= Logger.new(nil)
          Severity: Minor
          Found in lib/polipus.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

          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 initialize has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def initialize(job_name = 'polipus', urls = [], options = {})
                @job_name     = job_name
                @options      = OPTS.merge(options)
                @options[:queue_timeout] = 1 if @options[:queue_timeout] <= 0
                @logger       = @options[:logger]  ||= Logger.new(nil)
          Severity: Minor
          Found in lib/polipus.rb - About 1 hr to fix

            Method links has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def links
                  return @links.to_a unless @links.nil?
                  @links = Set.new
                  return [] unless doc
            
            
            Severity: Minor
            Found in lib/polipus/page.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 base has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                def base
                  @base = if doc
                            href = doc.search('//head/base/@href')
                            URI(href.to_s) unless href.nil? rescue nil
                          end unless @base
            Severity: Minor
            Found in lib/polipus/page.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_hash has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.from_hash(hash)
                  page = new(URI(hash['url']))
                  {
                    '@headers'       => hash['headers'] && !hash['headers'].empty? ? Marshal.load(hash['headers']) : { 'content-type' => [''] },
                    '@body'          => hash['body'],
            Severity: Minor
            Found in lib/polipus/page.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 initialize has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def initialize(uri, user_agent)
                    io = Robotex.get_robots_txt(uri, user_agent)
                    if !io || io.content_type != 'text/plain' || io.status != %w(200 OK)
                      io = StringIO.new("User-agent: *\nAllow: /\n")
                    end
            Severity: Minor
            Found in lib/polipus/robotex.rb - About 1 hr to fix

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

                      def allowed?(uri, user_agent)
                        return true unless @parsed
                        allowed = true
                        uri = URI.parse(uri.to_s) unless uri.is_a?(URI)
                        path = uri.request_uri
                Severity: Minor
                Found in lib/polipus/robotex.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 add has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                      def add(page)
                        @semaphore.synchronize do
                          obj = page.to_hash
                          @except.each { |e| obj.delete e.to_s }
                          obj[:id] = uuid(page)
                Severity: Minor
                Found in lib/polipus/storage/rethink_store.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