SonarLint : Java - Collapsible "if" statements should be merged (squid:S1066)
in some cases are multiple if statement whereas both the if statement can be merged together , so collapsible if statement should be merged it will improve the readability and maintainability of the codebase.
Non Compliant Code
Compliant Code
Example from sonar Source
Noncompliant Code Example
if (file != null) {
if (file.isFile() || file.isDirectory()) {
/* ... */
}
}
Compliant Solution
if (file != null && isFileOrDirectory(file)) {
/* ... */
}
private static boolean isFileOrDirectory(File file) {
return file.isFile() || file.isDirectory();
}