rapid7/metasploit-framework

View on GitHub
tools/hardware/elm327_relay.rb

Summary

Maintainability
D
1 day
Test Coverage

Method on_request_uri has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def on_request_uri(cli, request)
      if request.uri =~ /status$/i
        send_response_html(cli, get_status().to_json(), { 'Content-Type' => 'application/json' })
      elsif request.uri =~ /statistics$/i
        send_response_html(cli, get_stats().to_json(), { 'Content-Type' => 'applicaiton/json' })
Severity: Minor
Found in tools/hardware/elm327_relay.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 elm327_relay.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
Open

begin
  require 'serialport'
rescue LoadError => e
  gem = e.message.split.last
  abort "#{gem} gem is not installed. Please install with `gem install #{gem}' or, if using rvm, `rvm gemset install #{gem}' and try again."
Severity: Minor
Found in tools/hardware/elm327_relay.rb - About 2 hrs to fix

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

        def initialize(info={})
          # Set some defaults
          self.serial_port = "/dev/ttyUSB0"
          self.serial_baud = 115200
          begin
    Severity: Minor
    Found in tools/hardware/elm327_relay.rb - About 1 hr to fix

      Method on_request_uri has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def on_request_uri(cli, request)
            if request.uri =~ /status$/i
              send_response_html(cli, get_status().to_json(), { 'Content-Type' => 'application/json' })
            elsif request.uri =~ /statistics$/i
              send_response_html(cli, get_stats().to_json(), { 'Content-Type' => 'applicaiton/json' })
      Severity: Minor
      Found in tools/hardware/elm327_relay.rb - About 1 hr to fix

        Method isotpsend_and_wait has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def isotpsend_and_wait(srcid, dstid, data, timeout, maxpkts)
              result = {}
              result["success"] = false
              srcid = "%03X" % srcid.to_i(16)
              dstid = "%03X" % dstid.to_i(16)
        Severity: Minor
        Found in tools/hardware/elm327_relay.rb - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                      timeout = params["timeout"][0] if params.has_key? "timeout"
          Severity: Major
          Found in tools/hardware/elm327_relay.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        maxpkts = params["maxpkts"][0] if params.has_key? "maxpkts"
            Severity: Major
            Found in tools/hardware/elm327_relay.rb - About 45 mins to fix

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

                  def isotpsend_and_wait(srcid, dstid, data, timeout, maxpkts)
              Severity: Minor
              Found in tools/hardware/elm327_relay.rb - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status