Class: Reek::Smells::BooleanParameter

Inherits:
SmellDetector show all
Defined in:
lib/reek/smells/boolean_parameter.rb

Overview

A Boolean parameter effectively permits a method's caller to decide which execution path to take. The offending parameter is a kind of Control Couple.

Currently Reek can only detect a Boolean parameter when it has a default initializer.

Constant Summary

Constants inherited from SmellDetector

SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from SmellDetector

#smell_category, #smell_type, #smells_found, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SmellDetector

#config_for, #configure_with, contexts, default_config, default_smell_category, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_type, #value

Constructor Details

This class inherits a constructor from Reek::Smells::SmellDetector

Class Method Details

.smell_categoryObject


15
16
17
# File 'lib/reek/smells/boolean_parameter.rb', line 15

def self.smell_category
  'ControlCouple'
end

Instance Method Details

#examine_context(method_ctx) ⇒ Array<SmellWarning>

Checks whether the given method has any Boolean parameters.


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reek/smells/boolean_parameter.rb', line 24

def examine_context(method_ctx)
  method_ctx.parameters.default_assignments.select do |_param, value|
    [:true, :false].include?(value[0])
  end.map do |parameter, _value|
    SmellWarning.new self,
                     context: method_ctx.full_name,
                     lines: [method_ctx.exp.line],
                     message: "has boolean parameter '#{parameter}'",
                     parameters: { name: parameter.to_s }
  end
end