rapid7/metasploit-framework

View on GitHub
lib/rex/proto/dns/resolver.rb

Summary

Maintainability
F
4 days
Test Coverage

Method send_tcp has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
Open

    def send_tcp(packet, packet_data, nameservers, prox = @config[:proxies])
      ans = nil
      length = [packet_data.size].pack("n")
      nameservers.each do |ns, socket_options|
        socket = nil
Severity: Minor
Found in lib/rex/proto/dns/resolver.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 resolver.rb has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'net/dns/resolver'
require 'dnsruby'

module Rex
module Proto
Severity: Minor
Found in lib/rex/proto/dns/resolver.rb - About 5 hrs to fix

    Method send_udp has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def send_udp(packet,packet_data, nameservers)
          ans = nil
          nameservers.each do |ns, socket_options|
            begin
              config = {
    Severity: Minor
    Found in lib/rex/proto/dns/resolver.rb - About 4 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 send_tcp has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def send_tcp(packet, packet_data, nameservers, prox = @config[:proxies])
          ans = nil
          length = [packet_data.size].pack("n")
          nameservers.each do |ns, socket_options|
            socket = nil
    Severity: Major
    Found in lib/rex/proto/dns/resolver.rb - About 3 hrs to fix

      Method resolve_via_dns_server has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def resolve_via_dns_server(upstream_resolver, packet, type, _cls)
            method = self.use_tcp? ? :send_tcp : :send_udp
      
            # Store packet_data for performance improvements,
            # so methods don't keep on calling Packet#encode
      Severity: Minor
      Found in lib/rex/proto/dns/resolver.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 send has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def send(argument, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
            case argument
            when Dnsruby::Message
              packet = argument
            when Net::DNS::Packet, Resolv::DNS::Message
      Severity: Minor
      Found in lib/rex/proto/dns/resolver.rb - About 1 hr to fix

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

            def send(argument, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
              case argument
              when Dnsruby::Message
                packet = argument
              when Net::DNS::Packet, Resolv::DNS::Message
        Severity: Minor
        Found in lib/rex/proto/dns/resolver.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 a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(config = {})
              raise ResolverArgumentError, "Argument has to be Hash" unless config.kind_of? Hash
              # config.key_downcase!
              @config = Defaults.merge config
              @config[:config_file] ||= self.class.default_config_file
        Severity: Minor
        Found in lib/rex/proto/dns/resolver.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_udp has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def send_udp(packet,packet_data, nameservers)
              ans = nil
              nameservers.each do |ns, socket_options|
                begin
                  config = {
        Severity: Minor
        Found in lib/rex/proto/dns/resolver.rb - About 1 hr to fix

          Method resolve_via_dns_server has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def resolve_via_dns_server(upstream_resolver, packet, type, _cls)
                method = self.use_tcp? ? :send_tcp : :send_udp
          
                # Store packet_data for performance improvements,
                # so methods don't keep on calling Packet#encode
          Severity: Minor
          Found in lib/rex/proto/dns/resolver.rb - About 1 hr to fix

            Method simple_name_lookup has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def simple_name_lookup(upstream_resolver, packet, type, cls, &block)
                  return nil unless cls == Dnsruby::Classes::IN
            
                  # todo: make sure this will work if the packet has multiple questions, figure out how that's handled
                  name = packet.question.first.qname.to_s
            Severity: Minor
            Found in lib/rex/proto/dns/resolver.rb - About 1 hr to fix

              Method initialize has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def initialize(config = {})
                    raise ResolverArgumentError, "Argument has to be Hash" unless config.kind_of? Hash
                    # config.key_downcase!
                    @config = Defaults.merge config
                    @config[:config_file] ||= self.class.default_config_file
              Severity: Minor
              Found in lib/rex/proto/dns/resolver.rb - About 1 hr to fix

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

                    def search(name, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
                      return query(name,type,cls) if name.class == IPAddr
                      # If the name contains at least one dot then try it as is first.
                      if name.include? "."
                        @logger.debug "Search(#{name},#{Dnsruby::Types.new(type)},#{Dnsruby::Classes.new(cls)})"
                Severity: Minor
                Found in lib/rex/proto/dns/resolver.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 simple_name_lookup has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def simple_name_lookup(upstream_resolver, packet, type, cls, &block)
                Severity: Minor
                Found in lib/rex/proto/dns/resolver.rb - About 35 mins to fix

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

                      def simple_name_lookup(upstream_resolver, packet, type, cls, &block)
                        return nil unless cls == Dnsruby::Classes::IN
                  
                        # todo: make sure this will work if the packet has multiple questions, figure out how that's handled
                        name = packet.question.first.qname.to_s
                  Severity: Minor
                  Found in lib/rex/proto/dns/resolver.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