rapid7/metasploit-framework

View on GitHub
lib/msf/core/session_compatibility.rb

Summary

Maintainability
C
1 day
Test Coverage

Method session_incompatibility_reasons has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    def session_incompatibility_reasons(sess_or_sid)
      # Normalize the argument to an actual Session
      case sess_or_sid
      when ::Integer, ::String
        s = framework.sessions[sess_or_sid.to_i]
Severity: Minor
Found in lib/msf/core/session_compatibility.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 meterpreter_session_incompatibility_reasons has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def meterpreter_session_incompatibility_reasons(session)
      cmd_name_wildcards = module_info.dig('Compat', 'Meterpreter', 'Commands') || []
      cmd_names = Rex::Post::Meterpreter::CommandMapper.get_command_names.select do |cmd_name|
        cmd_name_wildcards.any? { |cmd_name_wildcard| ::File.fnmatch(cmd_name_wildcard, cmd_name) }
      end
Severity: Minor
Found in lib/msf/core/session_compatibility.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 meterpreter_session_incompatibility_reasons has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def meterpreter_session_incompatibility_reasons(session)
      cmd_name_wildcards = module_info.dig('Compat', 'Meterpreter', 'Commands') || []
      cmd_names = Rex::Post::Meterpreter::CommandMapper.get_command_names.select do |cmd_name|
        cmd_name_wildcards.any? { |cmd_name_wildcard| ::File.fnmatch(cmd_name_wildcard, cmd_name) }
      end
Severity: Minor
Found in lib/msf/core/session_compatibility.rb - About 1 hr to fix

    Method session_incompatibility_reasons has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def session_incompatibility_reasons(sess_or_sid)
          # Normalize the argument to an actual Session
          case sess_or_sid
          when ::Integer, ::String
            s = framework.sessions[sess_or_sid.to_i]
    Severity: Minor
    Found in lib/msf/core/session_compatibility.rb - About 1 hr to fix

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

          def setup
            alert_user
      
            if options['SESSION']&.required && session.blank?
              raise Msf::OptionValidateError, ['SESSION']
      Severity: Minor
      Found in lib/msf/core/session_compatibility.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 check_for_session_readiness has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def check_for_session_readiness(tries=6)
            session_ready_count = 0
            session_ready = false
            until session.sys or session_ready_count > tries
              session_ready_count += 1
      Severity: Minor
      Found in lib/msf/core/session_compatibility.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 ["missing Meterpreter features: #{command_names_for(missing_cmd_ids)}"] unless missing_cmd_ids.empty?
      Severity: Major
      Found in lib/msf/core/session_compatibility.rb - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status