app/services/rules/solver.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
90%

Method has too many lines. [17/10]
Open

    def validate_formulas(rule)
      return if rule.formulas.empty?

      facts = {}.merge(rule.fake_facts)
      rule.formulas.each do |formula|
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [17/10]
Open

    def solve!(message, facts_and_rules, debug = false)
      log "********** #{message} #{Time.new}\n#{JSON.pretty_generate(facts_and_rules)}\n" if debug
      begin
        solution = calculator.solve!(facts_and_rules)
      rescue TSort::Cyclic => cycle_error
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [12/10]
Open

    def validate_expression(formula)
      calculator.dependencies(
        Rules::ValuesMocker.mock_values(
          formula.expression,
          formula.rule.available_variables_for_values
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Useless assignment to variable - ignored.
Open

    rescue StandardError => ignored
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Use e instead of cycle_error.
Open

      rescue TSort::Cyclic => cycle_error
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop makes sure that rescued exceptions variables are named as expected.

The PreferredName config option takes a String. It represents the required name of the variable. Its default is e.

Example: PreferredName: e (default)

# bad
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => _e
  # do something
end

Example: PreferredName: exception

# bad
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => _exception
  # do something
end

Do not use Time.new without zone. Use one of Time.zone.now, Time.current, Time.new.in_time_zone, Time.new.utc, Time.new.getlocal, Time.new.xmlschema, Time.new.iso8601, Time.new.jisx0301, Time.new.rfc3339, Time.new.httpdate, Time.new.to_i, Time.new.to_f instead.
Open

      log "********** #{message} #{Time.new}\n#{JSON.pretty_generate(facts_and_rules)}\n" if debug
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop checks for the use of Time methods without zone.

Built on top of Ruby on Rails style guide (https://github.com/rubocop-hq/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/

Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

Example: EnforcedStyle: strict

# `strict` means that `Time` should be used with `zone`.

# bad
Time.now
Time.parse('2015-03-02 19:05:37')

# bad
Time.current
Time.at(timestamp).in_time_zone

# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')

Example: EnforcedStyle: flexible (default)

# `flexible` allows usage of `in_time_zone` instead of `zone`.

# bad
Time.now
Time.parse('2015-03-02 19:05:37')

# good
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')

# good
Time.current
Time.at(timestamp).in_time_zone

Use e instead of ignored.
Open

    rescue StandardError => ignored
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

This cop makes sure that rescued exceptions variables are named as expected.

The PreferredName config option takes a String. It represents the required name of the variable. Its default is e.

Example: PreferredName: e (default)

# bad
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => _e
  # do something
end

Example: PreferredName: exception

# bad
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => _exception
  # do something
end

Line is too long. [109/100]
Open

      rule.errors[:formulas] << "#{e.message}. Remove extra spaces or verify it's in the available variables"
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

Line is too long. [101/100]
Open

        raise SolvingError.new("a cycle has been created : " + cycle_error.message, facts_and_rules),
Severity: Minor
Found in app/services/rules/solver.rb by rubocop

There are no issues that match your filters.

Category
Status