Sha256: e1e91c0309efb77e6acef1180eeb4a1dcd2db7357a5539d6553c6ce2f18b46d8

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'simplabs/excellent/checks/cyclomatic_complexity_check'

module Simplabs

  module Excellent

    module Checks

      # This check reports blocks with a cyclomatic complexity metric score that is higher than the threshold. The cyclomatic complexity metric counts
      # the number of linearly independent paths through the code. This is basically the number of the following statements + 1:
      #
      # * +if+
      # * +else+
      # * +unless+
      # * +while+
      # * +until+
      # * +for+
      # * +rescue+
      # * +case+
      # * +when+
      # * +and+
      # * +or+
      #
      # ==== Applies to
      #
      # * blocks
      class CyclomaticComplexityBlockCheck < CyclomaticComplexityCheck

        DEFAULT_THRESHOLD = 4
      
        def initialize(options = {}) #:nodoc:
          threshold = options[:threshold] || DEFAULT_THRESHOLD
          super([Parsing::BlockContext], threshold)
        end
      
        def evaluate(context) #:nodoc:
          unless context.cc_score <= @threshold
            add_warning(context, '{{block}} has cyclomatic complexity of {{score}}.', { :block => context.full_name, :score => context.cc_score })
          end
        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excellent-1.7.2 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
excellent-1.7.1 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
excellent-1.7.0 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
excellent-1.6.0 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb