<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;Simulated Polymorphism occurs when&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;code uses a case statement (especially on a type field);&lt;/li&gt;
	&lt;li&gt;or code has several if statements in a row (especially if they&amp;#8217;re comparing against the same value);&lt;/li&gt;
	&lt;li&gt;or code uses instance_of?, kind_of?, is_a?, or === to decide what type it&amp;#8217;s working with;&lt;/li&gt;
	&lt;li&gt;or multiple conditionals in different places test the same value.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Conditional code is hard to read and understand, because the reader must hold more state in his head. When the same value is tested in multiple places throughout an application, any change to the set of possible values will require many methods and classes to change. Tests for the type of an object may indicate that the abstraction represented by that type is not completely defined (or understood).&lt;/p&gt;
&lt;h2&gt;Current Support in Reek&lt;/h2&gt;
&lt;p&gt;The Simulated Polymorphism detector is new in Reek version &lt;strong&gt;1.1.3.14&lt;/strong&gt;.&lt;br /&gt;
In the current implementation, Reek checks for multiple conditionals testing the same value throughout a single class.&lt;/p&gt;
&lt;h2&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Reek&amp;#8217;s Simulated Polymorphism detector currently offers the [[Basic Smell Options]], plus:&lt;/p&gt;
&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Option &lt;/th&gt;
		&lt;th&gt;Value &lt;/th&gt;
		&lt;th&gt;Effect &lt;/th&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt; &lt;code&gt;max_ifs&lt;/code&gt; &lt;/td&gt;
		&lt;td&gt;  integer &lt;/td&gt;
		&lt;td&gt; The maximum number of identical conditional tests permitted before Reek raises a warning. Defaults to 2. &lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;</body>
  <created-at type="datetime">2009-11-24T02:27:08-08:00</created-at>
  <id type="integer">323210</id>
  <permalink>simulated-polymorphism</permalink>
  <repository-id type="integer">49515</repository-id>
  <title>Simulated Polymorphism</title>
  <updated-at type="datetime">2009-09-12T12:45:28-07:00</updated-at>
  <user-id type="integer">23290</user-id>
</wiki>
