openjaf/cenit

View on GitHub
app/models/setup/triggers_formatter.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Method condition_apply has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def condition_apply(obj, before, field_name, condition)
      obj_v = obj.try(field_name)
      cond_v = valuate(condition['v'], obj_v.class)
      obj_values =
        if cond_v.is_a?(String) || (cond_v.is_a?(Array) && cond_v.detect { |e| e.is_a?(String) })
Severity: Minor
Found in app/models/setup/triggers_formatter.rb - About 2 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 valuate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def valuate(cond_v, klass)
      return if cond_v.nil?
      return cond_v if cond_v.is_a?(klass)
      cond_v = [cond_v] unless (is_array = cond_v.is_a?(Array))
      to_obj_class = CONVERSION_METHOD[klass]
Severity: Minor
Found in app/models/setup/triggers_formatter.rb - About 1 hr 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 format_triggers_on has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def format_triggers_on(field, required = false)
      begin
        send("#{field}=", json = send(field).gsub('=>', ':'))
        hash = JSON.parse(json)
        hash.delete('_')
Severity: Minor
Found in app/models/setup/triggers_formatter.rb - About 1 hr to fix

    Method format_triggers_on has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def format_triggers_on(field, required = false)
          begin
            send("#{field}=", json = send(field).gsub('=>', ':'))
            hash = JSON.parse(json)
            hash.delete('_')
    Severity: Minor
    Found in app/models/setup/triggers_formatter.rb - About 1 hr 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 field_triggers_apply_to? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def field_triggers_apply_to?(field, obj_now, obj_before = nil)
          r = true
          triggers_hash = JSON.parse(send(field))
          triggers_hash.each do |field_name, conditions|
            # LEGACY: Transform form old Hash conditions format to new Array conditions format.
    Severity: Minor
    Found in app/models/setup/triggers_formatter.rb - About 45 mins 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 op_between has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def op_between(obj_v, cond_v)
          return false if obj_v.nil? || cond_v.nil?
          min = cond_v[1].nil? ? true : obj_v >= cond_v[1]
          max = cond_v[2].nil? ? true : obj_v <= cond_v[2]
          min && max
    Severity: Minor
    Found in app/models/setup/triggers_formatter.rb - About 35 mins 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

    There are no issues that match your filters.

    Category
    Status