sgammon/GUST

View on GitHub
java/gust/backend/driver/spanner/SpannerUtil.java

Summary

Maintainability
A
30 mins
Test Coverage

Avoid too many return statements within this method.
Open

                    return maybeWrapType(pointer, Type.timestamp());
Severity: Major
Found in java/gust/backend/driver/spanner/SpannerUtil.java - About 30 mins to fix

Extract this nested ternary operation into an independent statement.
Open

               columnOpts.isPresent() && columnOpts.get().getSptype() != SpannerOptions.SpannerType.UNSPECIFIED_TYPE ?
                 resolveType(settings, fieldPointer, columnOpts.get().getSptype()) :
               resolveDefaultType(fieldPointer, settings);

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";
}

There are no issues that match your filters.

Category
Status