Class: Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck
- Inherits:
-
CyclomaticComplexityCheck
- Object
- Base
- CyclomaticComplexityCheck
- Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck
- Defined in:
- lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
Overview
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
Constant Summary collapse
- DEFAULT_THRESHOLD =
8
Instance Attribute Summary
Attributes inherited from Base
#interesting_files, #interesting_nodes, #warnings
Instance Method Summary collapse
-
#evaluate(context) ⇒ Object
:nodoc:.
-
#initialize(options = {}) ⇒ CyclomaticComplexityMethodCheck
constructor
:nodoc:.
Methods inherited from Base
#add_warning, #evaluate_node, #warnings_for
Constructor Details
#initialize(options = {}) ⇒ CyclomaticComplexityMethodCheck
:nodoc:
31 32 33 34 |
# File 'lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb', line 31 def initialize( = {}) #:nodoc: threshold = [:threshold] || DEFAULT_THRESHOLD super([:defn, :defs], threshold) end |
Instance Method Details
#evaluate(context) ⇒ Object
:nodoc:
36 37 38 39 40 |
# File 'lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb', line 36 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 |