rapid7/metasploit-framework

View on GitHub
lib/rex/proto/http/web_socket.rb

Summary

Maintainability
D
1 day
Test Coverage

Method wsloop has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def wsloop(opts = {}, &block)
      buffer = ''
      buffer_type = nil

      # since web sockets have their own tear down exchange, use a synchronization lock to ensure we aren't closed until
Severity: Minor
Found in lib/rex/proto/http/web_socket.rb - About 5 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

File web_socket.rb has 286 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'bindata'
require 'rex/post/channel'

module Rex::Proto::Http::WebSocket
  class WebSocketError < StandardError
Severity: Minor
Found in lib/rex/proto/http/web_socket.rb - About 2 hrs to fix

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

          def initialize(websocket, read_type: nil, write_type: :binary)
            initialize_abstraction
    
            # a read type of nil will handle both binary and text frames that are received
            raise ArgumentError, 'read_type must be nil, :binary or :text' unless [nil, :binary, :text].include?(read_type)
    Severity: Minor
    Found in lib/rex/proto/http/web_socket.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 wsloop has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def wsloop(opts = {}, &block)
          buffer = ''
          buffer_type = nil
    
          # since web sockets have their own tear down exchange, use a synchronization lock to ensure we aren't closed until
    Severity: Minor
    Found in lib/rex/proto/http/web_socket.rb - About 1 hr to fix

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

            def initialize(websocket, read_type: nil, write_type: :binary)
              initialize_abstraction
      
              # a read type of nil will handle both binary and text frames that are received
              raise ArgumentError, 'read_type must be nil, :binary or :text' unless [nil, :binary, :text].include?(read_type)
      Severity: Minor
      Found in lib/rex/proto/http/web_socket.rb - About 1 hr to fix

        Method wsclose has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def wsclose(opts = {})
              return if closed? # there's nothing to do if the underlying TCP socket has already been closed
        
              # this implementation doesn't handle the optional close reasons at all
              frame = Frame.new(header: { opcode: Opcode::CONNECTION_CLOSE })
        Severity: Minor
        Found in lib/rex/proto/http/web_socket.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 get_wsframe has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_wsframe(_opts = {})
              frame = Frame.new
              frame.header.read(self)
              payload_data = ''
              while payload_data.length < frame.payload_len
        Severity: Minor
        Found in lib/rex/proto/http/web_socket.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