File tree Expand file tree Collapse file tree 1 file changed +15
-18
lines changed
sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -6,33 +6,30 @@ <h2>Why is this an issue?</h2>
66< p > Instead, separate methods should be written.</ p >
77< p > This rule finds methods with a < code > boolean</ code > that’s used to determine which path to take through the method.</ p >
88< h3 > Noncompliant code example</ h3 >
9- < pre >
10- public String tempt (String name, boolean ofAge ) {
11- if (ofAge ) {
12- offerLiquor(name);
9+ < pre data-diff-id =" 1 " data-diff-type =" noncompliant " >
10+ public String feed (String name, boolean isHuman ) {
11+ if (isHuman ) {
12+ // implementation for human
1313 } else {
14- offerCandy(name);
14+ // implementation for animal
1515 }
1616}
1717
18- // ...
19- public void corrupt() {
20- tempt("Joe", false); // does this mean not to temp Joe?
21- }
18+ // Intent is not clear at call site
19+ feed("Max", false); // does this mean not to feed Max?
2220</ pre >
2321< h3 > Compliant solution</ h3 >
24- < pre >
25- public void temptAdult (String name) {
26- offerLiquor (name);
22+ < pre data-diff-id =" 1 " data-diff-type =" compliant " >
23+ public void feedHuman (String name) {
24+ offerSushi (name);
2725}
2826
29- public void temptChild (String name) {
30- offerCandy (name);
27+ public void feedAnimal (String name) {
28+ offerCarrot (name);
3129}
3230
33- // ...
34- public void corrupt() {
35- age < legalAge ? temptChild("Joe") : temptAdult("Joe");
36- }
31+ // Clear intent at call site
32+ feedHuman("Joe");
33+ feedAnimal("Max");
3734</ pre >
3835
You can’t perform that action at this time.
0 commit comments