eclipsepmdcode-complexity

Need enlightment about NPath complexity


I added PMD to my Eclipse workspace and I'm working on cleaning the code.

My most complex method says it has a NPath complexity of 804, ok no problem, it probably need refactoring.

But then I've something that look rather simple that has a NPath complexity of 3125, that seems just wrong :

public void toUpperParams() {
    valueParam1 = StringUtils.isNotEmpty(valueParam1) ? valueParam1.toUpperCase() : null;
    valueParam2 = StringUtils.isNotEmpty(valueParam2) ? valueParam2.toUpperCase() : null;
    valueParam3 = StringUtils.isNotEmpty(valueParam3) ? valueParam3.toUpperCase() : null;
    valueParam4 = StringUtils.isNotEmpty(valueParam4) ? valueParam4.toUpperCase() : null;
    valueParam5 = StringUtils.isNotEmpty(valueParam5) ? valueParam5.toUpperCase() : null;
}

Am I missing something ?


Solution

  • It seems that ternary increases the NPath factor. Below two explanations I could find:

    Question on Github

    Question on stackoverflow