Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sonar-collapsible if statements

I am getting the exception "collapsible if statement".

Through the sonar in the following code.

if(getSomething().equals(getSomething()){
  if(getsomehing.contains(getSomething()){

  }
}

Collapsible if statements These statements could be combined.

What is the meaning of this metric?

like image 218
user1552438 Avatar asked Jan 16 '23 18:01

user1552438


1 Answers

see the pmd explanation for this: http://qa.nuiton.org/sonar/rules/show/pmd:CollapsibleIfStatements?layout=false

PMD/Sonar identified, that you don't need 2 if statements, but can rather combine it to one using AND/OR opeartors.

this should be OK:

if (getSomething().equals(getSomething()) && getsomehing.contains(getSomething())) {
}
like image 59
Peter Butkovic Avatar answered Jan 21 '23 14:01

Peter Butkovic