fujaba/NetworkParser

View on GitHub
src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java

Summary

Maintainability
F
3 days
Test Coverage

File MQTTMessage.java has 399 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package de.uniks.networkparser.ext.io;

/*
The MIT License

Severity: Minor
Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 5 hrs to fix

    Method create has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public static MQTTMessage create(byte type, byte info, byte[] variableHeader) {
            MQTTMessage message = new MQTTMessage().withType(type);
            if (type == MESSAGE_TYPE_DISCONNECT) {
                return message;
            }
    Severity: Minor
    Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 4 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

    Method getVariableHeader has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        protected byte[] getVariableHeader() {
            if (type == MESSAGE_TYPE_PUBACK) {
                ByteBuffer buffer = new ByteBuffer();
                short id = (short) msgId;
                buffer.insert(id, false);
    Severity: Minor
    Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 3 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

    Method create has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static MQTTMessage create(byte type, byte info, byte[] variableHeader) {
            MQTTMessage message = new MQTTMessage().withType(type);
            if (type == MESSAGE_TYPE_DISCONNECT) {
                return message;
            }
    Severity: Major
    Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 3 hrs to fix

      Method getPayload has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public byte[] getPayload() {
              if (type == MESSAGE_TYPE_SUBSCRIBE || type == MESSAGE_TYPE_UNSUBSCRIBE || type == MESSAGE_TYPE_CONNECT) {
                  ByteBuffer buffer = new ByteBuffer();
                  if (type == MESSAGE_TYPE_SUBSCRIBE) {
                      for (int i = 0; i < names.length; i++) {
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 3 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

      MQTTMessage has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

      public class MQTTMessage {
          public static final byte MESSAGE_TYPE_CONNECT = 1;
          public static final byte MESSAGE_TYPE_CONNACK = 2;
          public static final byte MESSAGE_TYPE_PUBLISH = 3;
          public static final byte MESSAGE_TYPE_PUBACK = 4;
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 3 hrs to fix

        Method getVariableHeader has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected byte[] getVariableHeader() {
                if (type == MESSAGE_TYPE_PUBACK) {
                    ByteBuffer buffer = new ByteBuffer();
                    short id = (short) msgId;
                    buffer.insert(id, false);
        Severity: Minor
        Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                          if (type == MESSAGE_TYPE_CONNACK || type == MESSAGE_TYPE_DISCONNECT || type == MESSAGE_TYPE_PUBACK
                                  || type == MESSAGE_TYPE_SUBACK || type == MESSAGE_TYPE_PINGREQ || type == MESSAGE_TYPE_SUBSCRIBE
                                  || type == MESSAGE_TYPE_UNSUBSCRIBE || type == MESSAGE_TYPE_CONNECT
                                  || type == MESSAGE_TYPE_PUBLISH) {
                              return MQTTMessage.create(type, info, packet);
          Severity: Critical
          Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 1 hr to fix

            Method readFrom has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static MQTTMessage readFrom(DataInputStream in) {
                    if (in == null) {
                        return null;
                    }
                    MQTTMessage message = null;
            Severity: Minor
            Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 1 hr to fix

              Method readFrom has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static MQTTMessage readFrom(DataInputStream in) {
                      if (in == null) {
                          return null;
                      }
                      MQTTMessage message = null;
              Severity: Minor
              Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 1 hr 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

              Method getPayload has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public byte[] getPayload() {
                      if (type == MESSAGE_TYPE_SUBSCRIBE || type == MESSAGE_TYPE_UNSUBSCRIBE || type == MESSAGE_TYPE_CONNECT) {
                          ByteBuffer buffer = new ByteBuffer();
                          if (type == MESSAGE_TYPE_SUBSCRIBE) {
                              for (int i = 0; i < names.length; i++) {
              Severity: Minor
              Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 1 hr to fix

                Method getMessageInfo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected byte getMessageInfo() {
                        if (type == MESSAGE_TYPE_SUBSCRIBE || type == MESSAGE_TYPE_UNSUBSCRIBE) {
                            return (byte) (2 | (duplicate ? 8 : 0));
                        }
                        if (type == MESSAGE_TYPE_PUBLISH) {
                Severity: Minor
                Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 35 mins 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 true;
                Severity: Major
                Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return message;
                  Severity: Major
                  Found in src/main/java/de/uniks/networkparser/ext/io/MQTTMessage.java - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status