Nested ternaries are hard to read and can make the order of operations complex to understand.
func getReadableStatus(job: Job) -> String {
return job.isRunning ? "Running" : job.hasErrors ? "Failed" : "Succeeded"; // Noncompliant
}
Instead, use another line to express the nested operation in a separate statement.
func getReadableStatus(job: Job) -> String {
let status: String;
if (job.isRunning) {
status = "Running";
}
else {
status = job.hasErrors ? "Failed" : "Succeeded";
}
return status;
}