java/gust/backend/driver/spanner/SpannerUtil.java
Avoid too many return
statements within this method. Open
Open
return maybeWrapType(pointer, Type.timestamp());
- Create a ticketCreate a ticket
Extract this nested ternary operation into an independent statement. Open
Open
columnOpts.isPresent() && columnOpts.get().getSptype() != SpannerOptions.SpannerType.UNSPECIFIED_TYPE ?
resolveType(settings, fieldPointer, columnOpts.get().getSptype()) :
resolveDefaultType(fieldPointer, settings);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Just because you can do something, doesn't mean you should, and that's the case with nested ternary operations. Nesting ternary operators results in the kind of code that may seem clear as day when you write it, but six months later will leave maintainers (or worse - future you) scratching their heads and cursing.
Instead, err on the side of clarity, and use another line to express the nested operation as a separate statement.
Noncompliant Code Example
public String getReadableStatus(Job j) { return j.isRunning() ? "Running" : j.hasErrors() ? "Failed" : "Succeeded"; // Noncompliant }
Compliant Solution
public String getReadableStatus(Job j) { if (j.isRunning()) { return "Running"; } return j.hasErrors() ? "Failed" : "Succeeded"; }