rapid7/metasploit-framework

View on GitHub
lib/rbmysql/protocol.rb

Summary

Maintainability
F
4 days
Test Coverage

File protocol.rb has 575 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "socket"
require "timeout"
require "digest/sha1"
require "stringio"

Severity: Major
Found in lib/rbmysql/protocol.rb - About 1 day to fix

    Class Protocol has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Protocol
    
        VERSION = 10
        MAX_PACKET_LENGTH = 2**24-1
    
    
    Severity: Minor
    Found in lib/rbmysql/protocol.rb - About 4 hrs to fix

      Method read has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def read
            data = ''
            len = nil
            begin
              Timeout.timeout @read_timeout do
      Severity: Minor
      Found in lib/rbmysql/protocol.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 net2value has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.net2value(pkt, type, unsigned)
            case type
            when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB, Field::TYPE_JSON
              return pkt.lcs
            when Field::TYPE_TINY
      Severity: Minor
      Found in lib/rbmysql/protocol.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 net2value has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def self.net2value(pkt, type, unsigned)
            case type
            when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB, Field::TYPE_JSON
              return pkt.lcs
            when Field::TYPE_TINY
      Severity: Minor
      Found in lib/rbmysql/protocol.rb - About 1 hr to fix

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

            def self.value2net(v)
              case v
              when nil
                type = Field::TYPE_NULL
                val = ""
        Severity: Minor
        Found in lib/rbmysql/protocol.rb - About 1 hr to fix

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

              def read
                data = ''
                len = nil
                begin
                  Timeout.timeout @read_timeout do
          Severity: Minor
          Found in lib/rbmysql/protocol.rb - About 1 hr to fix

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

                def write(data)
                  begin
                    @sock.sync = false
                    if data.nil?
                      Timeout.timeout @write_timeout do
            Severity: Minor
            Found in lib/rbmysql/protocol.rb - About 1 hr to fix

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

                  def parse_record_packet
                    @packet.utiny  # skip first byte
                    null_bit_map = @packet.read((@fields.length+7+2)/8).unpack("b*").first
                    rec = @fields.each_with_index.map do |f, i|
                      if null_bit_map[i+2] == ?1
              Severity: Minor
              Found in lib/rbmysql/protocol.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
                    @insert_id = 0
                    @warning_count = 0
                    @gc_stmt_queue = []   # stmt id list which GC destroy.
                    set_state :INIT
              Severity: Minor
              Found in lib/rbmysql/protocol.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 value2net has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.value2net(v)
                    case v
                    when nil
                      type = Field::TYPE_NULL
                      val = ""
              Severity: Minor
              Found in lib/rbmysql/protocol.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 initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
              Severity: Minor
              Found in lib/rbmysql/protocol.rb - About 45 mins to fix

                Method serialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                      def self.serialize(client_flags, max_packet_size, charset_number, username, scrambled_password, databasename)
                Severity: Minor
                Found in lib/rbmysql/protocol.rb - About 45 mins to fix

                  Method authenticate has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def authenticate(user, passwd, db, flag, charset)
                  Severity: Minor
                  Found in lib/rbmysql/protocol.rb - About 35 mins to fix

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

                        def to_a
                          @fields.map do |f|
                            if s = @packet.lcs
                              unless f.type == Field::TYPE_BIT or f.charsetnr == Charset::BINARY_CHARSET_NUMBER
                                s = Charset.convert_encoding(s, @encoding)
                    Severity: Minor
                    Found in lib/rbmysql/protocol.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 write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def write(data)
                          begin
                            @sock.sync = false
                            if data.nil?
                              Timeout.timeout @write_timeout do
                    Severity: Minor
                    Found in lib/rbmysql/protocol.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

                    Avoid too many return statements within this method.
                    Open

                            return pkt.lcs
                    Severity: Major
                    Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return unsigned ? v : v < 0x8000_0000_0000_0000 ? v : v-0x10000_0000_0000_0000
                      Severity: Major
                      Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return RbMysql::Time.new(0, 0, 0, h, mi, s, sign!=0, sp)
                        Severity: Major
                        Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return t
                          Severity: Major
                          Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return RbMysql::Time.new(y, m, d, h, mi, s, false, sp)
                            Severity: Major
                            Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return pkt.ushort
                              Severity: Major
                              Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return pkt.read(4).unpack('e').first
                                Severity: Major
                                Found in lib/rbmysql/protocol.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return pkt.read(8).unpack('E').first
                                  Severity: Major
                                  Found in lib/rbmysql/protocol.rb - About 30 mins to fix

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

                                        def set_state(st)
                                          @state = st
                                          if st == :READY
                                            gc_disabled = GC.disable
                                            begin
                                    Severity: Minor
                                    Found in lib/rbmysql/protocol.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

                                    There are no issues that match your filters.

                                    Category
                                    Status