Added code example for npath

This commit is contained in:
oowekyala
2017-08-08 21:07:22 +02:00
parent 1105d62a29
commit 4be56ab274

View File

@ -123,35 +123,40 @@ class Foo { // +1, total Ncss = 12
<priority>3</priority>
<example>
<![CDATA[
void bar() { // This is something more complex than it needs to be,
if (y) { // it should be broken down into smaller methods or functions
for (j = 0; j < m; j++) {
if (j > r) {
doSomething();
while (f < 5 ) {
anotherThing();
f -= 27;
}
} else {
tryThis();
}
public class Foo {
public static void bar() { // Ncss = 252: reported!
boolean a, b = true;
try { // 2 * 2 + 2 = 6
if (true) { // 2
List buz = new ArrayList();
}
for(int i = 0; i < 19; i++) { // * 2
List buz = new ArrayList();
}
} catch(Exception e) {
if (true) { // 2
e.printStackTrace();
}
}
if ( r - n > 45) {
while (doMagic()) {
findRabbits();
}
while (j++ < 20) { // * 2
List buz = new ArrayList();
}
try {
doSomethingDangerous();
} catch (Exception ex) {
makeAmends();
} finally {
dontDoItAgain();
switch(j) { // * 7
case 1:
case 2: break;
case 3: j = 5; break;
case 4: if (b && a) { bar(); } break;
default: break;
}
do { // * 3
List buz = new ArrayList();
} while (a && j++ < 30);
}
}
]]>
</example>
</rule>