diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2301.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2301.html index bd8fffb0ab..a5c349a21b 100644 --- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2301.html +++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2301.html @@ -6,33 +6,30 @@

Why is this an issue?

Instead, separate methods should be written.

This rule finds methods with a boolean that’s used to determine which path to take through the method.

Noncompliant code example

-
-public String tempt(String name, boolean ofAge) {
-  if (ofAge) {
-    offerLiquor(name);
+
+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?
 

Compliant solution

-
-public void temptAdult(String name) {
-  offerLiquor(name);
+
+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 < legalAge ? temptChild("Joe") : temptAdult("Joe");
-}
+// Clear intent at call site
+feedHuman("Joe");
+feedAnimal("Max");