ece517-p3/expertiza

View on GitHub
app/helpers/chart_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for validate_optional_conf is too high. [24.84/15]
Open

    def self.validate_optional_conf(optionalConf, template)
      if optionalConf[:subtitle].nil?
        template.delete(:subtitle)
      else
        template[:subtitle] = {}
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for set_pie_data is too high. [17.29/15]
Open

    def self.set_pie_data(data, template)
      template[:series][0][:data] = []
      data.each do |obj|
        temp = []
        temp << obj[:name]
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for validate_optional_conf is too high. [9/7]
Open

    def self.validate_optional_conf(optionalConf, template)
      if optionalConf[:subtitle].nil?
        template.delete(:subtitle)
      else
        template[:subtitle] = {}
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method validate_optional_conf has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def self.validate_optional_conf(optionalConf, template)
      if optionalConf[:subtitle].nil?
        template.delete(:subtitle)
      else
        template[:subtitle] = {}
Severity: Minor
Found in app/helpers/chart_helper.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 dataAdapter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def self.dataAdapter(type, data, optionalConf)
      template = data_template[type]
      if type == :pie
        template = set_pie_data(data, template)
      else
Severity: Minor
Found in app/helpers/chart_helper.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

Do not prefix writer method names with set_.
Open

    def self.set_template_optional_params(template)
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop makes sure that accessor methods are named properly.

Example:

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

Replace class var @@chart_index with a class instance var.
Open

      @@chart_index += 1
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Replace class var @@header with a class instance var.
Open

      @@header = true
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Use snake_case for variable names.
Open

    def self.dataAdapter(type, data, optionalConf)
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
fooBar = 1

# good
foo_bar = 1

Example: EnforcedStyle: camelCase

# bad
foo_bar = 1

# good
fooBar = 1

Use snake_case for method names.
Open

    def self.dataAdapter(type, data, optionalConf)
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop makes sure that all methods use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
def fooBar; end

# good
def foo_bar; end

Example: EnforcedStyle: camelCase

# bad
def foo_bar; end

# good
def fooBar; end

Do not prefix reader method names with get_.
Open

    def get_id_str
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop makes sure that accessor methods are named properly.

Example:

# bad
def set_attribute(value)
end

# good
def attribute=(value)
end

# bad
def get_attribute
end

# good
def attribute
end

Use snake_case for variable names.
Open

    def self.validate_optional_conf(optionalConf, template)
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Example: EnforcedStyle: snake_case (default)

# bad
fooBar = 1

# good
foo_bar = 1

Example: EnforcedStyle: camelCase

# bad
foo_bar = 1

# good
fooBar = 1

Replace class var @@header with a class instance var.
Open

    @@header = false
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

Replace class var @@chart_index with a class instance var.
Open

    @@chart_index = 0
Severity: Minor
Found in app/helpers/chart_helper.rb by rubocop

This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

There are no issues that match your filters.

Category
Status