Showing 6 of 6 total issues
Method eval
has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring. Open
Open
def self.eval(expr, vars = {})
vars = Hash[*vars.merge(CONSTANTS).map {|k,v| [k.to_s.downcase, v] }.flatten]
stack, result, unary = [], [], true
expr.to_s.scan(TOKENIZER).each do |tok|
if tok == '('
- 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 eval
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def self.eval(expr, vars = {})
vars = Hash[*vars.merge(CONSTANTS).map {|k,v| [k.to_s.downcase, v] }.flatten]
stack, result, unary = [], [], true
expr.to_s.scan(TOKENIZER).each do |tok|
if tok == '('
Avoid deeply nested control flow statements. Open
Open
if Object.const_defined?(:Unit)
Unit(tok[1..-2])
else
raise(RuntimeError, 'Unit support not available')
end
Avoid deeply nested control flow statements. Open
Open
elsif unary && operator[3]
# Alternative prefix operator
stack << operator[3]
else
# Infix operator
Avoid deeply nested control flow statements. Open
Open
raise(NameError, "Symbol #{tok} is undefined") if !vars.include?(tok)
Avoid deeply nested control flow statements. Open
Open
stack << '*' if !unary