Sha256: 30bbd059af22e3a64a4b2e62f3cfffaef4121c16479d453a78fed2695f7f21f5

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')

module Reek
  module Smells

    #
    # 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.
    #
    class BooleanParameter < SmellDetector

      #
      # Checks whether the given method has a Boolean parameter.
      # Remembers any smells found.
      #
      def examine_context(method_ctx)
        method_ctx.parameters.default_assignments.each do |param, value|
          next unless [:true, :false].include?(value[0])
          smell = SmellWarning.new('ControlCouple', method_ctx.full_name, [method_ctx.exp.line],
            "has boolean parameter '#{param.to_s}'", @masked,
            @source, 'BooleanParameter', {'parameter' => param.to_s})
          @smells_found << smell
          #SMELL: serious duplication
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-1.2.7.2 lib/reek/smells/boolean_parameter.rb
reek-1.2.7.1 lib/reek/smells/boolean_parameter.rb
reek-1.2.7 lib/reek/smells/boolean_parameter.rb