File MessageSession.java
has 795 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.ext.io;
/*
The MIT License
MessageSession
has 46 methods (exceeds 20 allowed). Consider refactoring. Open
public class MessageSession {
public static final String TYPE_EMAIL = "EMAIL";
public static final String TYPE_XMPP = "XMPP";
public static final String TYPE_FCM = "FCM";
public static final String TYPE_PLAIN = "PLAIN";
Method sending
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public boolean sending(SocketMessage message) {
if (message == null) {
return false;
}
if (TYPE_XMPP.equals(this.type) || TYPE_FCM.equals(this.type)) {
- 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 sending
has 81 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean sending(SocketMessage message) {
if (message == null) {
return false;
}
if (TYPE_XMPP.equals(this.type) || TYPE_FCM.equals(this.type)) {
Method connectXMPP
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean connectXMPP(String sender, String password) {
this.type = TYPE_XMPP;
this.factory = javax.net.SocketFactory.getDefault();
if (isValid(sender) == false) {
return false;
Method connectFCM
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean connectFCM(String sender, String password) {
this.type = TYPE_FCM;
this.factory = SSLSocketFactory.getDefault();
if (isValid(sender) == false) {
return false;
Method connectAMQ
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean connectAMQ(NodeProxyBroker broker, String sender, String password) {
this.type = TYPE_AMQ;
if (this.port == 0) {
this.port = AMQP_PORT;
}
Method connectSMTP
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean connectSMTP(String sender, String password) {
this.type = TYPE_EMAIL;
this.factory = javax.net.SocketFactory.getDefault();
if (isValid(sender) == false) {
return false;
Method sending
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public MQTTMessage sending(NodeProxyBroker broker, MQTTMessage message, boolean answer) {
if (broker == null || message == null || out == null) {
return null;
}
if (message.isMessageIdRequired() && (message.getMessageId() == 0)) {
- 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 getLocalHost
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public String getLocalHost() {
InetAddress localHost;
String localHostName = null;
/* get our hostname and cache it for future use */
try {
- 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 sending
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public MQTTMessage sending(NodeProxyBroker broker, MQTTMessage message, boolean answer) {
if (broker == null || message == null || out == null) {
return null;
}
if (message.isMessageIdRequired() && (message.getMessageId() == 0)) {
Method getLoginText
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String getLoginText(String user, String password) {
if (user == null || password == null) {
return "";
}
byte[] userBytes = user.getBytes();
Method startTLS
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public boolean startTLS() {
try {
if (this.serverSocket == null) {
return 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 connectMQTT
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public boolean connectMQTT(NodeProxyBroker broker, String clientId, String sender, String password, int keepAlive,
int mqttVersion, boolean cleanSession) {
this.type = TYPE_MQTT;
if (host == null || host.isEmpty()) {
return false;
Method getLoginText
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private String getLoginText(String user, String password) {
if (user == null || password == null) {
return "";
}
byte[] userBytes = user.getBytes();
- 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 connectSMTP
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public boolean connectSMTP(String sender, String password) {
this.type = TYPE_EMAIL;
this.factory = javax.net.SocketFactory.getDefault();
if (isValid(sender) == false) {
return 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 write
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public boolean write(Object... values) {
if (values == null || out == null) {
return false;
}
try {
- 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 connectMQTT
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public boolean connectMQTT(NodeProxyBroker broker, String clientId, String sender, String password, int keepAlive,
int mqttVersion, boolean cleanSession) {
Method getByteResponse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected ByteBuffer getByteResponse() {
ByteBuffer response = new ByteBuffer();
if (in == null) {
return response;
}
- 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 getResponse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected BufferedBuffer getResponse() {
BufferedBuffer response = this.responseFactory.getNewList(false);
if (in == null) {
return response;
}
- 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 connectAMQ
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public boolean connectAMQ(NodeProxyBroker broker, String sender, String password) {
this.type = TYPE_AMQ;
if (this.port == 0) {
this.port = AMQP_PORT;
}
- 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 connectMQTT
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public boolean connectMQTT(NodeProxyBroker broker, String clientId, String sender, String password, int keepAlive,
int mqttVersion, boolean cleanSession) {
this.type = TYPE_MQTT;
if (host == null || host.isEmpty()) {
return 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 initSockets
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private boolean initSockets(String host, int port) throws UnsupportedEncodingException, IOException {
if (factory == null || host == null || host.isEmpty() || port < 1) {
return 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 connectXMPP
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public boolean connectXMPP(String sender, String password) {
this.type = TYPE_XMPP;
this.factory = javax.net.SocketFactory.getDefault();
if (isValid(sender) == false) {
return 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 close
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public boolean close() {
try {
if (in != null) {
in.close();
}
- 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 false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return doCommand("QUIT", RESPONSE_SERVICE_CLOSING_TRANSMISSION);
Avoid too many return
statements within this method. Open
return false;
Method checkServerResponse
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected boolean checkServerResponse(BufferedBuffer response, String code) {
if (response == null || code == null) {
return false;
}
if (response.length() < code.length()) {
- 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
XXX found Open
/* XXX - not correct for IPv6 */
- Exclude checks
XXX found Open
/* XXX - not correct for IPv6 */
- Exclude checks
These nested if statements could be combined Open
if (serverSocket != null && serverSocket.isBound()) {
localHost = serverSocket.getLocalAddress();
localHostName = localHost.getCanonicalHostName();
/* if we can't get our name, use local address literal */
if (localHostName == null)
- Read upRead up
- Exclude checks
CollapsibleIfStatements
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
Example:
void bar() {
if (x) { // original implementation
if (y) {
// do stuff
}
}
}
void bar() {
if (x && y) { // optimized implementation
// do stuff
}
}