Facing SonarQube Issue
Hi Everyone,
I m running SonarQube on an my AEM project, and the rule “Methods should not have high Cognitive Complexity” (java:S3776) keeps failing for this real utility method, even after I refactored parts into private helpers:
public List<Page> filterAndSortPages(List<Page> pages, Predicate<Page> filter) {
List<Page> result = new ArrayList<>();
for (Page page : pages) {
if (page != null && page.isValid()) {
if (page.getProperties().get("status", "draft").equals("published")) {
ValueMap vm = page.getProperties();
if (vm.containsKey("priority")) {
int priority = vm.get("priority", 0);
if (priority > 5) {
result.add(page);
}
}
}
}
}
result.sort(Comparator.comparingInt(p -> p.getProperties().get("priority", 0)).reversed());
return result;
}
I tried splitting the nested ifs into private methods, but didn't help, can someone help me here?