Parent

Roodi::Checks::CyclomaticComplexityBlockCheck

Checks cyclomatic complexity of a block against a specified limit.

The cyclomatic complexity is measured by the number of “if”, “unless”, “elsif”, “?:”, “while”, “until”, “for”, “rescue”, “case”, “when”, “&&”, “and”, “||” and “or” statements (plus one) in the body of the member. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests.

Generally, for a block, 1-2 is considered good, 3-4 ok, 5-8 consider re-factoring, and 8+ re-factor now!

Constants

DEFAULT_COMPLEXITY

Public Class Methods

new(options = {}) click to toggle source
# File lib/roodi/checks/cyclomatic_complexity_block_check.rb, line 17
def initialize(options = {})
  complexity = options['complexity'] || DEFAULT_COMPLEXITY
  super(complexity)
end

Public Instance Methods

evaluate_end_iter(node) click to toggle source
# File lib/roodi/checks/cyclomatic_complexity_block_check.rb, line 30
def evaluate_end_iter(node)
  decrease_depth
end
evaluate_matching_end() click to toggle source
# File lib/roodi/checks/cyclomatic_complexity_block_check.rb, line 34
def evaluate_matching_end
  add_error "Block cyclomatic complexity is #{@count}.  It should be #{@complexity} or less." unless @count <= @complexity
end
evaluate_start_iter(node) click to toggle source
# File lib/roodi/checks/cyclomatic_complexity_block_check.rb, line 26
def evaluate_start_iter(node)
  increase_depth
end
interesting_nodes() click to toggle source
# File lib/roodi/checks/cyclomatic_complexity_block_check.rb, line 22
def interesting_nodes
  [:iter] + COMPLEXITY_NODE_TYPES
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.