Sha256: 56d9cd67631e0bcfb9fa0584f65c6a89d6071ec6defe308f443095fe692799cc

Contents?: true

Size: 642 Bytes

Versions: 8

Compression:

Stored size: 642 Bytes

Contents

require 'roodi/checks/check'

module Roodi
  module Checks
    class CyclomaticComplexityCheck < Check
      COMPLEXITY_NODE_TYPES = [:if, :while, :until, :for, :rescue, :case, :when, :and, :or]

      def initialize(complexity)
        super()
        @complexity = complexity
      end
      
      protected
      
      def count_complexity(node)
        count_branches(node) + 1
      end

      private

      def count_branches(node)
        count = 0
        count = count + 1 if COMPLEXITY_NODE_TYPES.include? node.node_type
        node.children.each {|node| count += count_branches(node)}
        count
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
threedaymonk-roodi-1.3.8 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.5 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.6 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.2 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.4 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.4.0 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.7 lib/roodi/checks/cyclomatic_complexity_check.rb
roodi-1.3.3 lib/roodi/checks/cyclomatic_complexity_check.rb