LoboEvolution/LoboEvolution

View on GitHub
LoboCommon/src/main/java/org/loboevolution/common/RecordedInputStream.java

Summary

Maintainability
A
3 hrs
Test Coverage

Method read has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    @Override
    public int read() throws IOException {
        final int b;
        if (this.readPosition != -1 && this.readPosition < this.resetBuffer.length) {
            b = this.resetBuffer[this.readPosition];

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method read has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    @Override
    public int read(final byte[] buffer, final int offset, final int length) throws IOException {
        if (this.readPosition != -1 && this.readPosition < this.resetBuffer.length) {
            final int minLength = Math.min(this.resetBuffer.length - this.readPosition, length);
            System.arraycopy(this.resetBuffer, this.readPosition, buffer, offset, minLength);

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Merge this if statement with the enclosing one.
Open

                if (!this.hasReachedMaxBufferSize) {

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if (file != null) {
  if (file.isFile() || file.isDirectory()) {
    /* ... */
  }
}

Compliant Solution

if (file != null && isFileOrDirectory(file)) {
  /* ... */
}

private static boolean isFileOrDirectory(File file) {
  return file.isFile() || file.isDirectory();
}

Merge this if statement with the enclosing one.
Open

                if (!this.hasReachedMaxBufferSize) {

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if (file != null) {
  if (file.isFile() || file.isDirectory()) {
    /* ... */
  }
}

Compliant Solution

if (file != null && isFileOrDirectory(file)) {
  /* ... */
}

private static boolean isFileOrDirectory(File file) {
  return file.isFile() || file.isDirectory();
}

Rename "resetBuffer" which hides the field declared at line 51.
Open

        final byte[] resetBuffer = new byte[wholeBuffer.length - mp];

Overriding or shadowing a variable declared in an outer scope can strongly impact the readability, and therefore the maintainability, of a piece of code. Further, it could lead maintainers to introduce bugs because they think they're using one variable but are really using another.

Noncompliant Code Example

class Foo {
  public int myField;

  public void doSomething() {
    int myField = 0;
    ...
  }
}

See

There are no issues that match your filters.

Category
Status