Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,30 @@ <h2>Why is this an issue?</h2>
<p>Instead, separate methods should be written.</p>
<p>This rule finds methods with a <code>boolean</code> that’s used to determine which path to take through the method.</p>
<h3>Noncompliant code example</h3>
<pre>
public String tempt(String name, boolean ofAge) {
if (ofAge) {
offerLiquor(name);
<pre data-diff-id="1" data-diff-type="noncompliant">
public String feed(String name, boolean isHuman) {
if (isHuman) {
// implementation for human
} else {
offerCandy(name);
// implementation for animal
}
}

// ...
public void corrupt() {
tempt("Joe", false); // does this mean not to temp Joe?
}
// Intent is not clear at call site
feed("Max", false); // does this mean not to feed Max?
</pre>
<h3>Compliant solution</h3>
<pre>
public void temptAdult(String name) {
offerLiquor(name);
<pre data-diff-id="1" data-diff-type="compliant">
public void feedHuman(String name) {
offerSushi(name);
}

public void temptChild(String name) {
offerCandy(name);
public void feedAnimal(String name) {
offerCarrot(name);
}

// ...
public void corrupt() {
age &lt; legalAge ? temptChild("Joe") : temptAdult("Joe");
}
// Clear intent at call site
feedHuman("Joe");
feedAnimal("Max");
</pre>

Loading