fujaba/NetworkParser

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

Summary

Maintainability
F
6 days
Test Coverage

File MessageSession.java has 795 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package de.uniks.networkparser.ext.io;

/*
The MIT License

Severity: Major
Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 day to fix

    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";
    Severity: Minor
    Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 6 hrs to fix

      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)) {
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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 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)) {
      Severity: Major
      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 3 hrs to fix

        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;
        Severity: Minor
        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

          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;
          Severity: Minor
          Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

            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;
                    }
            Severity: Minor
            Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

              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;
              Severity: Minor
              Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

                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)) {
                Severity: Minor
                Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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 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 {
                Severity: Minor
                Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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 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)) {
                Severity: Minor
                Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

                  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();
                  Severity: Minor
                  Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

                    Method startTLS has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public boolean startTLS() {
                            try {
                                if (this.serverSocket == null) {
                                    return false;
                                }
                    Severity: Minor
                    Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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 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;
                    Severity: Minor
                    Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 1 hr to fix

                      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();
                      Severity: Minor
                      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 55 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

                      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;
                      Severity: Minor
                      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 55 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

                      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 {
                      Severity: Minor
                      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 55 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

                      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) {
                      Severity: Major
                      Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 50 mins to fix

                        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;
                                }
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 45 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

                        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;
                                }
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 45 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

                        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;
                                }
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 45 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

                        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;
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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

                        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;
                                }
                        
                        
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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

                        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;
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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

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

                            public boolean close() {
                                try {
                                    if (in != null) {
                                        in.close();
                                    }
                        Severity: Minor
                        Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.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/MessageSession.java - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                      return doCommand("QUIT", RESPONSE_SERVICE_CLOSING_TRANSMISSION);
                              Severity: Major
                              Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

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

                                  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()) {
                                  Severity: Minor
                                  Found in src/main/java/de/uniks/networkparser/ext/io/MessageSession.java - About 25 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

                                  XXX found
                                  Open

                                                  /* XXX - not correct for IPv6 */

                                  XXX found
                                  Open

                                                      /* XXX - not correct for IPv6 */

                                  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)

                                  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
                                   }
                                  }

                                  There are no issues that match your filters.

                                  Category
                                  Status