Sha256: d24c561e0275d9f33a6b5d886215fc283ca9ddad00416eb94a3d5b00903bb020

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require 'simplabs/excellent/checks/cyclomatic_complexity_check'

module Simplabs

  module Excellent

    module Checks

      # This check reports methods 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
      #
      # * methods
      class CyclomaticComplexityMethodCheck < CyclomaticComplexityCheck

        DEFAULT_THRESHOLD = 8

        def initialize(options = {}) #:nodoc:
          options[:threshold] ||= DEFAULT_THRESHOLD
          super([Parsing::MethodContext, Parsing::SingletonMethodContext], options)
        end

        def evaluate(context) #:nodoc:
          unless context.cc_score <= @threshold
            add_warning(context, '{{method}} has cyclomatic complexity of {{score}}.', { :method => 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-2.1.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
excellent-2.1.0 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
excellent-2.0.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
excellent-2.0.0 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb