fujaba/NetworkParser

View on GitHub
src/main/java/de/uniks/networkparser/bytes/ByteTokener.java

Summary

Maintainability
F
6 days
Test Coverage

Method decodeValue has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring.
Open

    public Object decodeValue(byte type, Buffer buffer, int end, MapEntity map) {
        if (buffer == null || buffer.remaining() < 1) {
            return null;
        }
        if (type == ByteTokener.DATATYPE_NULL) {
Severity: Minor
Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 1 day 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 decodeValue has 149 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public Object decodeValue(byte type, Buffer buffer, int end, MapEntity map) {
        if (buffer == null || buffer.remaining() < 1) {
            return null;
        }
        if (type == ByteTokener.DATATYPE_NULL) {
Severity: Major
Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 5 hrs to fix

    File ByteTokener.java has 397 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package de.uniks.networkparser.bytes;
    
    /*
    NetworkParser
    The MIT License
    Severity: Minor
    Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 5 hrs to fix

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

          public ByteItem encodeValue(Object value, MapEntity filter) {
              ByteEntity msgEntity = new ByteEntity();
              if (msgEntity.setValues(value)) {
                  return msgEntity;
              } else {
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.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 encode has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          @Override
          public ByteItem encode(Object entity, MapEntity map) {
              SendableEntityCreator creator = getCreatorClass(entity);
              if (creator == null) {
                  return null;
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.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 decodeClazz has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public Object decodeClazz(Buffer buffer, SendableEntityCreator eventCreater, MapEntity map) {
              if (eventCreater == null) {
                  ByteMessage e = new ByteMessage();
                  if (buffer != null)
                      e.withValue(buffer.array(-1, true));
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.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 encode has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          @Override
          public ByteItem encode(Object entity, MapEntity map) {
              SendableEntityCreator creator = getCreatorClass(entity);
              if (creator == null) {
                  return null;
      Severity: Minor
      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 1 hr to fix

        Method addClazzType has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            private boolean addClazzType(ByteList msg, String clazzName, MapEntity map) {
                if (map == null || clazzName == null) {
                    return false;
                }
                try {
        Severity: Minor
        Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.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 encodeValue has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public ByteItem encodeValue(Object value, MapEntity filter) {
                ByteEntity msgEntity = new ByteEntity();
                if (msgEntity.setValues(value)) {
                    return msgEntity;
                } else {
        Severity: Minor
        Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 1 hr to fix

          Method addClazzType has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private boolean addClazzType(ByteList msg, String clazzName, MapEntity map) {
                  if (map == null || clazzName == null) {
                      return false;
                  }
                  try {
          Severity: Minor
          Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 1 hr to fix

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

                public Object decodeClazz(Buffer buffer, SendableEntityCreator eventCreater, MapEntity map) {
                    if (eventCreater == null) {
                        ByteMessage e = new ByteMessage();
                        if (buffer != null)
                            e.withValue(buffer.array(-1, true));
            Severity: Minor
            Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      for (Iterator<?> i = list.iterator(); i.hasNext();) {
                                          Object item = i.next();
                                          eventCreater.setValue(entity, property, item, SendableEntityCreator.NEW);
                                      }
              Severity: Major
              Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 45 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

                              return new Date(buffer.getLong());
                  Severity: Major
                  Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return decodeClazz(buffer, eventCreater, map);
                    Severity: Major
                    Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return values;
                      Severity: Major
                      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return values;
                        Severity: Major
                        Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return Short.valueOf(buffer.getShort());
                          Severity: Major
                          Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return buffer.array(len, false);
                            Severity: Major
                            Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return null;
                              Severity: Major
                              Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return decodeClazz(buffer, eventCreater, map);
                                Severity: Major
                                Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                      return "";
                                  Severity: Major
                                  Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return null;
                                    Severity: Major
                                    Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return values;
                                      Severity: Major
                                      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return null;
                                        Severity: Major
                                        Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return Float.valueOf(buffer.getFloat());
                                          Severity: Major
                                          Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                                return null;
                                            Severity: Major
                                            Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return decodeClazz(buffer, eventCreater, map);
                                              Severity: Major
                                              Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return decodeClazz(buffer, eventCreater, map);
                                                Severity: Major
                                                Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return null;
                                                  Severity: Major
                                                  Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                        return new String(buffer.array(len, false), getCharset());
                                                    Severity: Major
                                                    Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return decodeClazz(buffer, eventCreater, map);
                                                      Severity: Major
                                                      Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return Long.valueOf(buffer.getLong());
                                                        Severity: Major
                                                        Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return Integer.valueOf(buffer.getInt());
                                                          Severity: Major
                                                          Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                        return Double.valueOf(buffer.getDouble());
                                                            Severity: Major
                                                            Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return map.getVisitedObjects(pos);
                                                              Severity: Major
                                                              Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                            return map.getVisitedObjects(pos);
                                                                Severity: Major
                                                                Found in src/main/java/de/uniks/networkparser/bytes/ByteTokener.java - About 30 mins to fix

                                                                  These nested if statements could be combined
                                                                  Open

                                                                                      if (clazzName.substring(0, pos).equals(lastClazz.substring(0, pos))) {
                                                                                          byte[] bytes = clazzName.substring(pos + 1).getBytes(getCharset());
                                                                                          msg.add(new ByteEntity().withValue(DATATYPE_CLAZZPACKAGE, bytes));
                                                                                          return true;
                                                                                      }

                                                                  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