ursinn/MinecraftServer

View on GitHub
src/main/java/com/github/joshj1091/mcserver/protocol/Protocol.java

Summary

Maintainability
A
3 hrs
Test Coverage

Method getPacket has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public static Packet getPacket(int state, Direction direction, ByteReader reader, int id) {
        if (state == 0) {
            if (direction == Direction.SERVERBOUND) {
                if (id == 0x00) {
                    return new HandshakePacket(reader);
Severity: Minor
Found in src/main/java/com/github/joshj1091/mcserver/protocol/Protocol.java - About 2 hrs to fix

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

Avoid too many return statements within this method.
Open

        return null;
Severity: Major
Found in src/main/java/com/github/joshj1091/mcserver/protocol/Protocol.java - About 30 mins to fix

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.
Open

    public static Packet getPacket(int state, Direction direction, ByteReader reader, int id) {

Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

See

Merge this if statement with the enclosing one.
Open

                if (id == 0x00) {

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 (direction == Direction.SERVERBOUND) {

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 (id == 0x00) {

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();
}

There are no issues that match your filters.

Category
Status