0

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 ?

TheBakker
  • 2,852
  • 2
  • 28
  • 49

2 Answers2

1

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

Question on Guthub

Question on stackoverflow

Community
  • 1
  • 1
Tom
  • 1,387
  • 3
  • 19
  • 30
0

I don't think you miss anything. According to my calculation, NPath should be 10 based on the definition, which was given in the following article: NPath complexity

Csuki
  • 1,297
  • 8
  • 21