minad/evaluator

View on GitHub

Showing 6 of 6 total issues

Method eval has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
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 == '('
Severity: Minor
Found in lib/evaluator.rb - About 7 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

Method eval has 52 lines of code (exceeds 25 allowed). Consider refactoring.
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 == '('
Severity: Major
Found in lib/evaluator.rb - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                    if Object.const_defined?(:Unit)
                      Unit(tok[1..-2])
                    else
                      raise(RuntimeError, 'Unit support not available')
                    end
    Severity: Major
    Found in lib/evaluator.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

              elsif unary && operator[3]
                # Alternative prefix operator
                stack << operator[3]
              else
                # Infix operator
      Severity: Major
      Found in lib/evaluator.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                        raise(NameError, "Symbol #{tok} is undefined") if !vars.include?(tok)
        Severity: Major
        Found in lib/evaluator.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    stack << '*' if !unary
          Severity: Major
          Found in lib/evaluator.rb - About 45 mins to fix
            Severity
            Category
            Status
            Source
            Language