Method parse_payload
has 101 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parse_payload(payload)
if not payload.instance_of?Array or payload.nil? or payload.length < 2
raise "Invalid Argument"
end
Cyclomatic complexity for parse_payload is too high. [25/6] Open
def parse_payload(payload)
if not payload.instance_of?Array or payload.nil? or payload.length < 2
raise "Invalid Argument"
end
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
File mindwave.rb
has 297 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "mindwave/version"
require 'serialport'
require 'bindata'
require 'logger'
Method parse_payload
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def parse_payload(payload)
if not payload.instance_of?Array or payload.nil? or payload.length < 2
raise "Invalid Argument"
end
- 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
Method run
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def run
tmpbyte = 0;
@runner = true
- 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
Class Headset
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class Headset
# -----------------------
# :section: Request Codes
# -----------------------
Cyclomatic complexity for run is too high. [8/6] Open
def run
tmpbyte = 0;
@runner = true
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method run
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run
tmpbyte = 0;
@runner = true
Method initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(headsetid=nil,device='/dev/ttyUSB0', connectserial=true,rate=115200, log=Logger.new(STDOUT))
TODO found Open
# TODO: implement connection with headsetid
- Exclude checks
Put one space between the method name and the first argument. Open
if not payload.instance_of?Array or payload.nil? or payload.length < 2
- Read upRead up
- Exclude checks
Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.
Alternatively, extra spaces can be added to align the argument with something on a preceding or following line, if the AllowForAlignment config parameter is true.
Example:
# bad
something x
something y, z
something'hello'
# good
something x
something y, z
something 'hello'
Literal true
appeared as a condition. Open
while true
- Read upRead up
- Exclude checks
This cop checks for literals used as the conditions or as operands in and/or expressions serving as the conditions of if/while/until.
Example:
# bad
if 20
do_something
end
Example:
# bad
if some_var && true
do_something
end
Example:
# good
if some_var && some_condition
do_something
end