Sha256: 0e98d969cb9e5a434a1489229261f548408e9da95cf3213b86c4d2f23f716a2d

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 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:
          threshold = options[:threshold] || DEFAULT_THRESHOLD
          super([:defn, :defs], threshold)
        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

12 entries across 12 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
excellent-1.5.4 lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb