The code below takes in an array of package names and dependencies in the format {Package1: Dependency, Package2: Dependency} and puts them in a hashmap to be returned. According to my interviewer, the method has a cyclomatic complexity of 12, which was is too high to be acceptable. However, I have ran metrics on the code which reported that the complexity is actually 2.
Can someone tell me why the complexity would be so high and how to simplify it for a lower cyclomatic complexity? I am at a loss here.
public static HashMap<String, String> parseDependencies(String[] args) {
HashMap<String, String> pairs = new HashMap<String, String>();
for (int i = 0; i < args.length; i++) {
if (!args[i].contains(": ") || args[i].startsWith(": ")) {
logger.log(Level.WARNING, ENTRY + args[i] + FORMATTING);
continue;
}
String[] entry = args[i].split(": ");
if (entry.length < 2) {
pairs.put(entry[0], null);
} else {
pairs.put(entry[0], entry[1]);
}
}
return pairs;
}