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.exceptions;

import org.json.JSONException;

/**
src/main/java/javapns/notification/exceptions/PayloadMaxSizeExceededException.java on lines 1..37

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 63.

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.notification.exceptions;

/**
 * Thrown when a payload exceeds the maximum size allowed.
 *
src/main/java/javapns/notification/exceptions/PayloadMaxSizeProbablyExceededException.java on lines 1..40

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 63.

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 pushSimplePayloadUsingThreads has 7 arguments (exceeds 4 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) {
Severity: Major
Found in src/test/java/javapns/test/NotificationTest.java - About 50 mins to fix

    Method combined has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      public static PushedNotifications combined(final String message, final int badge, final String sound, final Object keystore, final String password, final boolean production, final Object devices) throws CommunicationException, KeystoreException {
    Severity: Major
    Found in src/main/java/javapns/Push.java - About 50 mins to fix

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

        public VPNPayload(final int payloadVersion, final String payloadOrganization, final String payloadIdentifier, final String payloadDisplayName, final String userDefinedName, final boolean overridePrimary, final String vpnType) throws JSONException {
          super(payloadVersion, "com.apple.vpn.managed", payloadOrganization, payloadIdentifier, payloadDisplayName);
          final JSONObject payload = getPayload();
          payload.put("UserDefinedName", userDefinedName);
          payload.put("OverridePrimary", overridePrimary);
      Severity: Major
      Found in src/main/java/javapns/notification/management/VPNPayload.java and 2 other locations - About 50 mins to fix
      src/main/java/javapns/notification/management/CalDAVPayload.java on lines 13..19
      src/main/java/javapns/notification/management/WiFiPayload.java on lines 12..18

      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 62.

      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 3 locations. Consider refactoring.
      Open

        public CalDAVPayload(final int payloadVersion, final String payloadOrganization, final String payloadIdentifier, final String payloadDisplayName, final String calDAVHostName, final String calDAVUsername, final boolean calDAVUseSSL) throws JSONException {
          super(payloadVersion, "com.apple.caldav.account", payloadOrganization, payloadIdentifier, payloadDisplayName);
          final JSONObject payload = getPayload();
          payload.put("CalDAVHostName", calDAVHostName);
          payload.put("CalDAVUsername", calDAVUsername);
      src/main/java/javapns/notification/management/VPNPayload.java on lines 16..22
      src/main/java/javapns/notification/management/WiFiPayload.java on lines 12..18

      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 62.

      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 3 locations. Consider refactoring.
      Open

        public WiFiPayload(final int payloadVersion, final String payloadOrganization, final String payloadIdentifier, final String payloadDisplayName, final String ssidStr, final boolean hiddenNetwork, final String encryptionType) throws JSONException {
          super(payloadVersion, "com.apple.wifi.managed", payloadOrganization, payloadIdentifier, payloadDisplayName);
          final JSONObject payload = getPayload();
          payload.put("SSID_STR", ssidStr);
          payload.put("HIDDEN_NETWORK", hiddenNetwork);
      Severity: Major
      Found in src/main/java/javapns/notification/management/WiFiPayload.java and 2 other locations - About 50 mins to fix
      src/main/java/javapns/notification/management/CalDAVPayload.java on lines 13..19
      src/main/java/javapns/notification/management/VPNPayload.java on lines 16..22

      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 62.

      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 pushSpecificPayloadSize has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        private static void pushSpecificPayloadSize(final String keystore, final String password, final String token, final boolean production, final boolean checkWhenAdding, final int targetPayloadSize) throws CommunicationException, KeystoreException, JSONException {
      Severity: Minor
      Found in src/test/java/javapns/test/SpecificNotificationTests.java - About 45 mins to fix

        Method estimatePayloadSizeAfterAdding has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          private int estimatePayloadSizeAfterAdding(final String propertyName, final Object propertyValue) {
            try {
              int estimatedSize = getPayloadAsBytesUnchecked().length;
              if (propertyName != null && propertyValue != null) {
                estimatedSize += 6; // ,"":""
        Severity: Minor
        Found in src/main/java/javapns/notification/Payload.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

        Avoid deeply nested control flow statements.
        Open

                    if (foundFirstFail) {
                      notificationsToResend.add(notification);
                    } else {
                      foundFirstFail = true;
                    }
        Severity: Major
        Found in src/main/java/javapns/notification/PushNotificationManager.java - About 45 mins to fix

          Method addDevice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            public Device addDevice(final String id, String token) throws Exception {
              if ((id == null) || (id.trim().equals(""))) {
                throw new NullIdException();
              } else if ((token == null) || (token.trim().equals(""))) {
                throw new NullDeviceTokenException();

          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

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

          package javapns.devices.exceptions;
          
          /**
           * Thrown when the given id is null
           *
          Severity: Major
          Found in src/main/java/javapns/devices/exceptions/NullIdException.java and 2 other locations - About 45 mins to fix
          src/main/java/javapns/devices/exceptions/DuplicateDeviceException.java on lines 1..37
          src/main/java/javapns/devices/exceptions/UnknownDeviceException.java on lines 1..37

          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 55.

          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 put has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            void put(final String propertyName, final Object propertyValue, final JSONObject object, final boolean opt) throws JSONException {
              try {
                if (isPayloadSizeEstimatedWhenAdding()) {
                  final int maximumPayloadSize = getMaximumPayloadSize();
                  final int estimatedPayloadSize = estimatePayloadSizeAfterAdding(propertyName, propertyValue);
          Severity: Minor
          Found in src/main/java/javapns/notification/Payload.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 payload has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            public static PushedNotifications payload(final Payload payload, final Object keystore, final String password, final boolean production, final int numberOfThreads, final Object devices) throws Exception {
          Severity: Minor
          Found in src/main/java/javapns/Push.java - About 45 mins to fix

            Method validateKeystoreParameter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              public static void validateKeystoreParameter(Object keystore) throws InvalidKeystoreReferenceException {
                if (keystore == null) {
                  throw new InvalidKeystoreReferenceException((Object) null);
                }
                if (keystore instanceof KeyStore) {
            Severity: Minor
            Found in src/main/java/javapns/communication/KeystoreManager.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

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

            package javapns.devices.exceptions;
            
            /**
             * Thrown when a Device already exist and we try to add it a second time
             *
            src/main/java/javapns/devices/exceptions/NullIdException.java on lines 1..37
            src/main/java/javapns/devices/exceptions/UnknownDeviceException.java on lines 1..37

            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 55.

            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 wrapKeystoreException has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              static KeystoreException wrapKeystoreException(final Exception e) {
                if (e != null) {
                  final String msg = e.toString();
                  if (msg.contains("javax.crypto.BadPaddingException")) {
                    return new InvalidKeystorePasswordException();
            Severity: Minor
            Found in src/main/java/javapns/communication/KeystoreManager.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

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

            package javapns.devices.exceptions;
            
            /**
             * Thrown when we try to retrieve a device that doesn't exist
             *
            src/main/java/javapns/devices/exceptions/DuplicateDeviceException.java on lines 1..37
            src/main/java/javapns/devices/exceptions/NullIdException.java on lines 1..37

            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 55.

            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.ConnectionToAppleServer;
            import javapns.communication.exceptions.KeystoreException;
            import javapns.notification.AppleNotificationServer;
            Severity: Minor
            Found in src/main/java/javapns/feedback/ConnectionToFeedbackServer.java and 1 other location - About 40 mins to fix
            src/main/java/javapns/notification/ConnectionToNotificationServer.java on lines 1..32

            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 52.

            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.notification;
            
            import javapns.communication.ConnectionToAppleServer;
            import javapns.communication.exceptions.KeystoreException;
            
            
            src/main/java/javapns/feedback/ConnectionToFeedbackServer.java on lines 1..32

            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 52.

            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

            Severity
            Category
            Status
            Source
            Language