1
Besides applying high cohesion and low coupling, how to handle codes like this? They may even be legible but this excess of logical operators, I do not see it possible to refactor even with switch-case
.
if (!entry.isDirectory()
&& !entry.getName().startsWith("__MACOSX/")
&& !entry.getName().startsWith("_images/")
&& !entry.getName().contains("/_images")
&& !entry.getName().contains("/._")
&& !entry.getName().contains("/_img")
&& !entry.getName().contains("/imgs")
&& !entry.getName().contains("/_old")) {
String filename = Util.buildFilename(nome);
filenameMap.put(filename, nome);
if (!nome.startsWith("[.]")
&& (nome.toLowerCase().endsWith(".swf")
|| nome.toLowerCase().endsWith(".gif")
|| nome.toLowerCase().endsWith(".jpg") || nome
.toLowerCase().endsWith(".jpeg"))) {
files.add(dest + nome);
}
File destFile = FileUtils.getFile(dest, filename);
copyInputStream(zipFile.getInputStream(entry),
new BufferedOutputStream(new FileOutputStream(destFile)));
}
Sonarqube
Expressions should not be Too Complex
The Complexity of an Expression is defined by the number of &&, || and condition ? ifTrue : ifFalse Operators it contains. A single Expression’s Complexity should not become Too high to Keep the code readable.
I think it would help you to have better answers if you included in your question what the intention (i.e., the function) of this code snippet is. If you want to "filter" file patterns, maybe the best answer is really a combination of the two you already have: create a function that gets the file and a list of patterns to ignore, and then use regular expressions to check the file for each pattern in the list.
– Luiz Vieira
Any answer solved the problem?
– Maniero