File MQTTMessage.java
has 399 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.ext.io;
/*
The MIT License
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;
}
- Read upRead up
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);
- Read upRead up
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;
}
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++) {
- Read upRead up
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;
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);
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);
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;
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;
- Read upRead up
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++) {
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) {
- Read upRead up
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;
Avoid too many return
statements within this method. Open
return message;