tools/hardware/elm327_relay.rb
Method on_request_uri
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
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' })
- Read upRead up
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
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."
Method initialize
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def initialize(info={})
# Set some defaults
self.serial_port = "/dev/ttyUSB0"
self.serial_baud = 115200
begin
Method on_request_uri
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
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' })
Method isotpsend_and_wait
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
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)
Avoid deeply nested control flow statements. Open
Open
timeout = params["timeout"][0] if params.has_key? "timeout"
Avoid deeply nested control flow statements. Open
Open
maxpkts = params["maxpkts"][0] if params.has_key? "maxpkts"
Method isotpsend_and_wait
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def isotpsend_and_wait(srcid, dstid, data, timeout, maxpkts)