Sha256: 5c3246eaf2f62454851ff9c2d8cb13db66d43d54410dd158ad6059859ef26cce
Contents?: true
Size: 1.16 KB
Versions: 9
Compression:
Stored size: 1.16 KB
Contents
require 'roodi/checks/cyclomatic_complexity_check' module Roodi module Checks # 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! class CyclomaticComplexityBlockCheck < CyclomaticComplexityCheck DEFAULT_COMPLEXITY = 4 def initialize(options = {}) complexity = options['complexity'] || DEFAULT_COMPLEXITY super(complexity) end def interesting_nodes [:iter] end def evaluate(node) complexity = count_complexity(node) add_error "Block cyclomatic complexity is #{complexity}. It should be #{@complexity} or less." unless complexity <= @complexity end end end end
Version data entries
9 entries across 9 versions & 2 rubygems