jenkinsci/hpe-application-automation-tools-plugin

View on GitHub
src/main/java/com/microfocus/application/automation/tools/pc/PcClient.java

Summary

Maintainability
A
2 hrs
Test Coverage

Avoid too many return statements within this method.
Open

        return 0;

    Avoid too many return statements within this method.
    Open

                return 0;

      Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.
      Open

          private PcRunResponse waitForRunState(int runId, RunState completionState, int interval) throws InterruptedException,

      Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

      See

      Refactor this method to reduce its Cognitive Complexity from 25 to the 15 allowed.
      Open

          public void waitForRunToPublishOnTrendReport(int runId, String trendReportId) throws PcException, IOException, InterruptedException {

      Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

      See

      Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.
      Open

          private void setCorrectTrendReportID() throws IOException, PcException {

      Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

      See

      Refactor this method to reduce its Cognitive Complexity from 36 to the 15 allowed.
      Open

          public int startRun() throws NumberFormatException, ClientProtocolException, PcException, IOException {

      Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

      See

      Define a constant instead of duplicating this literal "%s - %s" 20 times.
      Open

                  logger.println(String.format("%s - %s", dateFormatter.getDate(), e.getMessage()));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      public void run() {
        prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
        execute("action1");
        release("action1");
      }
      
      @SuppressWarning("all")                            // Compliant - annotations are excluded
      private void method1() { /* ... */ }
      @SuppressWarning("all")
      private void method2() { /* ... */ }
      
      public String method3(String a) {
        System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
        return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
      }
      

      Compliant Solution

      private static final String ACTION_1 = "action1";  // Compliant
      
      public void run() {
        prepare(ACTION_1);                               // Compliant
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      This block of commented-out lines of code should be removed.
      Open

              //     return String.format( HyperlinkNote.encodeTo(filePath, "View trend report " + trendReportId));

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      Extract this nested try block into a separate method.
      Open

                      try {

      Nesting try/catch blocks severely impacts the readability of source code because it makes it too difficult to understand which block will catch which exception.

      This block of commented-out lines of code should be removed.
      Open

                      // logger.println(String.format("%s - Error on getTrendReportByXML: %s ", dateFormatter.getDate(), e));

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      Define a constant instead of duplicating this literal "%s: %s " 7 times.
      Open

                              "%s: %s \n" +

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      public void run() {
        prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
        execute("action1");
        release("action1");
      }
      
      @SuppressWarning("all")                            // Compliant - annotations are excluded
      private void method1() { /* ... */ }
      @SuppressWarning("all")
      private void method2() { /* ... */ }
      
      public String method3(String a) {
        System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
        return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
      }
      

      Compliant Solution

      private static final String ACTION_1 = "action1";  // Compliant
      
      public void run() {
        prepare(ACTION_1);                               // Compliant
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      This block of commented-out lines of code should be removed.
      Open

              //  logger.print(res);

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      Add a default case to this switch.
      Open

              switch (model.getPostRunAction()) {

      The requirement for a final default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken.

      Noncompliant Code Example

      switch (param) {  //missing default clause
        case 0:
          doSomething();
          break;
        case 1:
          doSomethingElse();
          break;
      }
      
      switch (param) {
        default: // default clause should be the last one
          error();
          break;
        case 0:
          doSomething();
          break;
        case 1:
          doSomethingElse();
          break;
      }
      

      Compliant Solution

      switch (param) {
        case 0:
          doSomething();
          break;
        case 1:
          doSomethingElse();
          break;
        default:
          error();
          break;
      }
      

      Exceptions

      If the switch parameter is an Enum and if all the constants of this enum are used in the case statements, then no default clause is expected.

      Example:

      public enum Day {
          SUNDAY, MONDAY
      }
      ...
      switch(day) {
        case SUNDAY:
          doSomething();
          break;
        case MONDAY:
          doSomethingElse();
          break;
      }
      

      See

      Define a constant instead of duplicating this literal "%s - %s: %s" 6 times.
      Open

                      logger.println(String.format("%s - %s: %s", dateFormatter.getDate(), Messages.UsingProxy(), model.getProxyOutURL(true)));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      public void run() {
        prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
        execute("action1");
        release("action1");
      }
      
      @SuppressWarning("all")                            // Compliant - annotations are excluded
      private void method1() { /* ... */ }
      @SuppressWarning("all")
      private void method2() { /* ... */ }
      
      public String method3(String a) {
        System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
        return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
      }
      

      Compliant Solution

      private static final String ACTION_1 = "action1";  // Compliant
      
      public void run() {
        prepare(ACTION_1);                               // Compliant
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      This block of commented-out lines of code should be removed.
      Open

      //            java.lang.reflect.Method rootMethod =  res.getClass().getMethod("getTrendReport" + dataType.toString() + "DataRowsList");

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      This block of commented-out lines of code should be removed.
      Open

                      //  logger.println("No such method exception: " + e);

      Programmers should not comment out code as it bloats programs and reduces readability.

      Unused code should be deleted and can be retrieved from source control history if required.

      Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
      Open

                      } catch (InterruptedException ex) {

      InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the fact that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.

      Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:

      If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

      Noncompliant Code Example

      public void run () {
        try {
          while (true) {
            // do stuff
          }
        }catch (InterruptedException e) { // Noncompliant; logging is not enough
          LOGGER.log(Level.WARN, "Interrupted!", e);
        }
      }
      

      Compliant Solution

      public void run () {
        try {
          while (true) {
            // do stuff
          }
        }catch (InterruptedException e) {
          LOGGER.log(Level.WARN, "Interrupted!", e);
          // Restore interrupted state...
          Thread.currentThread().interrupt();
        }
      }
      

      See

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

                  response = restProxy.startRun(testID,
                          testInstance,
                          new TimeslotDuration(model.getTimeslotDurationHours(true),model.getTimeslotDurationMinutes(true)),
                          model.getPostRunAction().getValue(),
                          model.isVudsMode(),
      src/main/java/com/microfocus/application/automation/tools/pc/PcClient.java on lines 208..213

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

      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

                          response = restProxy.startRun(testID,
                                  testInstance,
                                  new TimeslotDuration(model.getTimeslotDurationHours(true) ,model.getTimeslotDurationMinutes(true)),
                                  model.getPostRunAction().getValue(),
                                  model.isVudsMode(),
      src/main/java/com/microfocus/application/automation/tools/pc/PcClient.java on lines 161..166

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

      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

      There are no issues that match your filters.

      Category
      Status