Как я могу уменьшить когнитивную сложность в этом блоке? Кстати, как это может быть больше, чем разрешено 15?JAVA

Программисты JAVA общаются здесь
Anonymous
Как я могу уменьшить когнитивную сложность в этом блоке? Кстати, как это может быть больше, чем разрешено 15?

Сообщение Anonymous »

У меня есть этот код: < /p>

Код: Выделить всё

 private void processMedia(Integer mediaId, List hiresPhysicalPaths) {
final AtomicBoolean isHls = new AtomicBoolean(false);
for (String hiresPhysicalPath : hiresPhysicalPaths) {
REPORT.info("Process media version {} for media {} ", hiresPhysicalPath, mediaId);
String folderName = StringUtils.substringBefore(hiresPhysicalPath, "/");
File dir = new File(MediaRepositoryTools.getCurrentMediaPhysicalRootPath(App.getApplicationSession()), folderName);
REPORT.info("Dir : {}", dir);
File[] directoryListing = dir.listFiles();
if (directoryListing == null) {
REPORT.warn("Dir is not really a directory");
return;
}
String mediaIdString = mediaId.toString();
// loop pour savoir si le média est HLS ou pas
for (File child : directoryListing) {
String ext = FilenameUtils.getExtension(child.getName()).toLowerCase();
String childFileName = FilenameUtils.getBaseName(child.getName());
//If m3u8 file ex : 3180734-9u83wns9eh-m3u8.m3u8
try {
if (isMediaHls(mediaIdString, childFileName, ext)) {
miseAJourFichierHLS(child);
REPORT.info("Le fichier m3u8 a été mis à jour pour la version : {} du média {} ", hiresPhysicalPath, mediaId);
} else {
REPORT.info("Le fichier m3u8 n'a pas été mis à jour pour la version : {} du média {} ", hiresPhysicalPath, mediaId);
}
} catch (IOException e) {
REPORT.error("Unable to update the HLS file for media " + mediaId, e);
}
isHls.set(true);

if (childFileName.startsWith(mediaIdString) && isFileNeededToBeDeleted(child.getName(), isHls.get())) {
this.copyOrDelete(child);
}
}
}
App.getService(TransactionService.class).withTransaction(() -> this.updatePreviewGeneratedFlagForMedia(mediaId, isHls.get()));
}

Sonar сказал мне, чтобы я уменьшил когнитивную сложность с 16 до 15, я не знаю, как это может быть так сильно, поскольку там нет никаких вложенных условий, возможно, я ошибаюсь.>

Подробнее здесь: https://stackoverflow.com/questions/729 ... an-this-be

Вернуться в «JAVA»