Skip to content

Commit 36267e3

Browse files
committed
Add some smelly code
This should trigger warnings in Code Climate
1 parent 3a91a3f commit 36267e3

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package cc.altius.FASP;
2+
3+
public class BadCode {
4+
private int a, b, c, d, e, f, g, h; // Too many fields
5+
6+
// Method with too many parameters
7+
public void doSomething(int param1, int param2, int param3, int param4, int param5) {
8+
// Nested control flow beyond threshold
9+
if (param1 > 0) {
10+
if (param2 > 0) {
11+
if (param3 > 0) {
12+
if (param4 > 0) {
13+
if (param5 > 0) {
14+
System.out.println("Too deep!");
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}
21+
22+
// Complex method with high cyclomatic complexity
23+
public int calculateSomething(int x) {
24+
int result = 0;
25+
26+
// Multiple return statements
27+
if (x < 0) return -1;
28+
if (x == 0) return 0;
29+
if (x > 100) return 100;
30+
if (x % 2 == 0) return x * 2;
31+
if (x % 3 == 0) return x * 3;
32+
33+
// Complex logic with many branches
34+
for (int i = 0; i < x; i++) {
35+
if (i % 2 == 0) {
36+
result += i;
37+
} else if (i % 3 == 0) {
38+
result += i * 2;
39+
} else if (i % 5 == 0) {
40+
result += i * 3;
41+
} else {
42+
result += 1;
43+
}
44+
}
45+
46+
return result;
47+
}
48+
49+
// Duplicate code block 1
50+
public void duplicateMethod1() {
51+
int sum = 0;
52+
for (int i = 0; i < 100; i++) {
53+
sum += i;
54+
System.out.println("Processing: " + i);
55+
if (i % 2 == 0) {
56+
sum += 5;
57+
}
58+
}
59+
}
60+
61+
// Duplicate code block 2
62+
public void duplicateMethod2() {
63+
int sum = 0;
64+
for (int i = 0; i < 100; i++) {
65+
sum += i;
66+
System.out.println("Processing: " + i);
67+
if (i % 2 == 0) {
68+
sum += 5;
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)