OK, SonarQube has its definition of complexity, but I disagree on return being part of it.
The definition of complexity, as I see it, is the number of possible code paths within a method.
But "return" is not a code path; it _exits_ the method.
Consider this code, which I see waaaay too often:
----
public void someMethod()
{
if (someCondition) {
// big
// chunk
// of
// code
// here
}
}
----
Let's say the complexity of this method is n.
The way I would always write such a method instead is as such:
----
public void someMethod()
{
if (!someCondition)
return;
// big
// chunk
// of
// code
// here
}
----
Yet, due to the way SonarQube's Java plugin calculates the complexity, it would, artificially in this case, increment the complexity by 1... Even though the end code turns out to be more obvious.
Similarly, continue or break do not create other code paths; they just branch. Here as well, I disagree with both of them adding to complexity... Other code sample:
----
while (whatever) {
if (someCondition) {
// big
// chunk
// of
// code
// here
}
}
----
Complexity n; contrast with:
----
while (whatever) {
if (!someCondition)
continue;
// big
// chunk
// of
// code
// here
}
----
Again, to my eyes, this is an artificial increase of the complexity by 1.
Regards,