rapid7/metasploit-framework

View on GitHub
lib/rex/ui/text/shell.rb

Summary

Maintainability
F
3 days
Test Coverage

Method format_prompt has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

  def format_prompt(str)
    return str unless framework

    # find the active session
    session = framework.sessions.values.find { |session| session.interacting }
Severity: Minor
Found in lib/rex/ui/text/shell.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

Method run has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  def run(&block)
    begin
      require 'pry'
      # pry history will not be loaded by default when pry is used as a breakpoint like `binding.pry`
      Pry.config.history_load = false
Severity: Minor
Found in lib/rex/ui/text/shell.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

File shell.rb has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'rex/text/color'

module Rex
module Ui
module Text
Severity: Minor
Found in lib/rex/ui/text/shell.rb - About 3 hrs to fix

    Method format_prompt has 78 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def format_prompt(str)
        return str unless framework
    
        # find the active session
        session = framework.sessions.values.find { |session| session.interacting }
    Severity: Major
    Found in lib/rex/ui/text/shell.rb - About 3 hrs to fix

      Method run has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def run(&block)
          begin
            require 'pry'
            # pry history will not be loaded by default when pry is used as a breakpoint like `binding.pry`
            Pry.config.history_load = false
      Severity: Minor
      Found in lib/rex/ui/text/shell.rb - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                  formatted << (sysinfo.nil? ? default : sysinfo['Computer'])
        Severity: Major
        Found in lib/rex/ui/text/shell.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    formatted << (sysinfo.nil? ? default : sysinfo['Architecture'])
          Severity: Major
          Found in lib/rex/ui/text/shell.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      formatted << (session.respond_to?(:fs) ? session.fs.dir.getwd(refresh: false) : default)
            Severity: Major
            Found in lib/rex/ui/text/shell.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        formatted << (session.respond_to?(:sys) ? session.sys.config.getuid(refresh: false) : default)
              Severity: Major
              Found in lib/rex/ui/text/shell.rb - About 45 mins to fix

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

                  def initialize(prompt, prompt_char = '>', histfile = nil, framework = nil, name = nil)
                Severity: Minor
                Found in lib/rex/ui/text/shell.rb - About 35 mins to fix

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

                    def get_input_line
                      line = "\\\n"
                      prompt_needs_reset = false
                  
                      self.cont_flag = false
                  Severity: Minor
                  Found in lib/rex/ui/text/shell.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 init_tab_complete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def init_tab_complete
                      if (self.input and self.input.supports_readline)
                        # Unless cont_flag because there's no tab complete for continuation lines
                        self.input = Input::Readline.new(lambda { |str| tab_complete(str) unless cont_flag })
                        self.input.output = self.output
                  Severity: Minor
                  Found in lib/rex/ui/text/shell.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