mlaccetti/JavaPNS

View on GitHub

Showing 107 of 107 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

package javapns.notification;

import javapns.communication.AppleServerBasicImpl;
import javapns.communication.ConnectionToAppleServer;
import javapns.communication.exceptions.KeystoreException;
src/main/java/javapns/feedback/AppleFeedbackServerBasicImpl.java on lines 1..66

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 116.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

package javapns.feedback;

import javapns.communication.AppleServerBasicImpl;
import javapns.communication.ConnectionToAppleServer;
import javapns.communication.exceptions.KeystoreException;
src/main/java/javapns/notification/AppleNotificationServerBasicImpl.java on lines 1..67

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 116.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

  static String getProxyHost(final AppleServer server) {
    String host = server != null ? server.getProxyHost() : null;
    if (host != null && host.length() > 0) {
      return host;
    } else {
Severity: Minor
Found in src/main/java/javapns/communication/ProxyManager.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 getProxyPort has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  static int getProxyPort(final AppleServer server) {
    String host = server != null ? server.getProxyHost() : null;
    if (host != null && host.length() > 0) {
      return server.getProxyPort();
    } else {
Severity: Minor
Found in src/main/java/javapns/communication/ProxyManager.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 test_Issue102 has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private static void test_Issue102(final String keystore, final String password, String token, final boolean production) {
    try {
      System.out.println("");
      System.out.println("TESTING ISSUE #102");
      final int devices = 10000;
Severity: Minor
Found in src/test/java/javapns/test/SpecificNotificationTests.java - About 1 hr to fix

    Method doTunnelHandshake has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      private void doTunnelHandshake(final Socket tunnel, final String host, final int port) throws IOException {
    
        final OutputStream out = tunnel.getOutputStream();
    
        final String msg = "CONNECT " + host + ":" + port + " HTTP/1.0\n" + "User-Agent: BoardPad Server" + "\r\n\r\n";
    Severity: Minor
    Found in src/main/java/javapns/communication/ConnectionToAppleServer.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 doTunnelHandshake has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private void doTunnelHandshake(final Socket tunnel, final String host, final int port) throws IOException {
    
        final OutputStream out = tunnel.getOutputStream();
    
        final String msg = "CONNECT " + host + ":" + port + " HTTP/1.0\n" + "User-Agent: BoardPad Server" + "\r\n\r\n";
    Severity: Minor
    Found in src/main/java/javapns/communication/ConnectionToAppleServer.java - About 1 hr to fix

      Method asDevices has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public static List<Device> asDevices(final Object rawList) {
          final List<Device> list = new ArrayList<>();
          if (rawList == null) {
            return list;
          }
      Severity: Minor
      Found in src/main/java/javapns/devices/Devices.java - About 1 hr to fix

        Method processedFailedNotifications has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private int processedFailedNotifications() throws CommunicationException, KeystoreException {
            if (useEnhancedNotificationFormat) {
              logger.debug("Reading responses");
              int responsesReceived = ResponsePacketReader.processResponses(this);
              while (responsesReceived > 0) {
        Severity: Minor
        Found in src/main/java/javapns/notification/PushNotificationManager.java - About 1 hr to fix

          Method getMessage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            private byte[] getMessage(String deviceToken, final Payload payload, final int identifier, final PushedNotification message) throws IOException, Exception {
              logger.debug("Building Raw message from deviceToken and payload");
          
              /* To test with a corrupted or invalid token, uncomment following line*/
          
          
          Severity: Minor
          Found in src/main/java/javapns/notification/PushNotificationManager.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 getMessage has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public String getMessage() {
              if (command == 8) {
                final String prefix = "APNS: [" + identifier + "] "; //APNS ERROR FOR MESSAGE ID #" + identifier + ": ";
                if (status == 0) {
                  return prefix + "No errors encountered";
          Severity: Minor
          Found in src/main/java/javapns/notification/ResponsePacket.java - About 1 hr to fix

            Method verifyKeystoreContent has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private static void verifyKeystoreContent(final KeyStore keystore) throws KeystoreException {
                try {
                  int numberOfCertificates = 0;
                  final Enumeration<String> aliases = keystore.aliases();
                  while (aliases.hasMoreElements()) {
            Severity: Minor
            Found in src/main/java/javapns/communication/KeystoreManager.java - About 1 hr to fix

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

                static void printPushedNotifications(final List<PushedNotification> notifications) {
                  final List<PushedNotification> failedNotifications = PushedNotification.findFailedNotifications(notifications);
                  final List<PushedNotification> successfulNotifications = PushedNotification.findSuccessfulNotifications(notifications);
                  final int failed = failedNotifications.size();
                  final int successful = successfulNotifications.size();
              Severity: Minor
              Found in src/test/java/javapns/test/NotificationTest.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 pushSimplePayloadUsingThreads has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                private static void pushSimplePayloadUsingThreads(final String keystore, final String password, final boolean production, final String token, final boolean simulation, final int devices, final int threads) {
                  try {
              
                    System.out.println("Creating PushNotificationManager and AppleNotificationServer");
                    final AppleNotificationServer server = new AppleNotificationServerBasicImpl(keystore, password, production);
              Severity: Minor
              Found in src/test/java/javapns/test/NotificationTest.java - About 1 hr to fix

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

                  private static PushedNotifications sendPayloads(final Object keystore, final String password, final boolean production, final Object payloadDevicePairs) throws CommunicationException, KeystoreException {
                    final PushedNotifications notifications = new PushedNotifications();
                    if (payloadDevicePairs == null) {
                      return notifications;
                    }
                Severity: Minor
                Found in src/main/java/javapns/Push.java - About 1 hr to fix

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                        for (int i = 0; i < devices; i++) {
                          String tokenToUse = token;
                          if (tokenToUse == null || tokenToUse.length() != 64) {
                            tokenToUse = "123456789012345678901234567890123456789012345678901234567" + (1000000 + i);
                          }
                  Severity: Major
                  Found in src/test/java/javapns/test/NotificationTest.java and 1 other location - About 1 hr to fix
                  src/test/java/javapns/test/SpecificNotificationTests.java on lines 238..244

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 76.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          for (int i = 0; i < devices; i++) {
                            String tokenToUse = token;
                            if (tokenToUse == null || tokenToUse.length() != 64) {
                              tokenToUse = "123456789012345678901234567890123456789012345678901234567" + (1000000 + i);
                            }
                  Severity: Major
                  Found in src/test/java/javapns/test/SpecificNotificationTests.java and 1 other location - About 1 hr to fix
                  src/test/java/javapns/test/NotificationTest.java on lines 168..174

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 76.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

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

                    private static void pushTest(final String[] args) throws CommunicationException, KeystoreException {
                      final String keystore = args[0];
                      final String password = args[1];
                      final String token = args[2];
                      final boolean production = args.length >= 4 && args[3].equalsIgnoreCase("production");
                  Severity: Minor
                  Found in src/test/java/javapns/test/NotificationTest.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 sendPayload has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    private static PushedNotifications sendPayload(final Payload payload, final Object keystore, final String password, final boolean production, final Object devices) throws CommunicationException, KeystoreException {
                      final PushedNotifications notifications = new PushedNotifications();
                      if (payload == null) {
                        return notifications;
                      }
                  Severity: Minor
                  Found in src/main/java/javapns/Push.java - About 1 hr to fix

                    Method readResponsePacketData has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      private static ResponsePacket readResponsePacketData(final InputStream input) throws IOException {
                        final int command = input.read();
                        if (command < 0) {
                          return null;
                        }
                    Severity: Minor
                    Found in src/main/java/javapns/notification/ResponsePacketReader.java - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language