CloudSlang/cs-actions

View on GitHub
cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java

Summary

Maintainability
F
5 days
Test Coverage

Method copyRemoteToLocal has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    private static boolean copyRemoteToLocal(Session session, String srcPath, String destPath) {
        FileOutputStream fos = null;
        Channel channel = null;
        try {
            // exec 'scp -f rfile' remotely

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

File SCPService.java has 355 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright 2021-2024 Open Text
 * This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *

    Method copyRemoteToLocal has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static boolean copyRemoteToLocal(Session session, String srcPath, String destPath) {
            FileOutputStream fos = null;
            Channel channel = null;
            try {
                // exec 'scp -f rfile' remotely

      Method copyLocalToRemote has 67 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static boolean copyLocalToRemote(Session session, String srcPath, String destPath) {
              FileInputStream fis = null;
              OutputStream out = null;
              boolean ptimestamp = true;
              Channel channel = null;

        Method executeSCPCopyFile has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public Map<String, String> executeSCPCopyFile(SCPCopyFileInputs inputs) {
                Map<String, String> results = new HashMap<>();
                boolean successfullyCopied = false;
        
                try {

          Method executeSCPRemoteCopyFile has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public Map<String, String> executeSCPRemoteCopyFile(SCPRemoteCopyFileInputs inputs) {
                  Map<String, String> results = new HashMap<>();
                  boolean successfullyCopied = false;
                  File temporaryDestFile = null;
          
          

            Method copyLocalToRemote has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                private static boolean copyLocalToRemote(Session session, String srcPath, String destPath) {
                    FileInputStream fis = null;
                    OutputStream out = null;
                    boolean ptimestamp = true;
                    Channel channel = null;

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

                public Map<String, String> executeSCPCopyFile(SCPCopyFileInputs inputs) {
                    Map<String, String> results = new HashMap<>();
                    boolean successfullyCopied = false;
            
                    try {

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

                public Map<String, String> executeSCPRemoteCopyFile(SCPRemoteCopyFileInputs inputs) {
                    Map<String, String> results = new HashMap<>();
                    boolean successfullyCopied = false;
                    File temporaryDestFile = null;
            
            

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

                public static int checkAck(InputStream in) throws IOException {
                    int b = in.read();
                    // b may be 0 for success,
                    //          1 for error,
                    //          2 for fatal error,

            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 results;
            Severity: Major
            Found in cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return true;
              Severity: Major
              Found in cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java - About 30 mins to fix

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

                                case "to":
                                    try {
                                        successfullyCopied = CompletableFuture.supplyAsync(() -> copyLocalToRemote(session, inputs.getLocalFile(), inputs.getRemoteFile()))
                                                .get(Integer.parseInt(inputs.getConnectionTimeout()) * 1000L, TimeUnit.SECONDS);
                                    } catch (TimeoutException e) {
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 81..96

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

                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

                                case "from":
                                    try {
                                        successfullyCopied = CompletableFuture.supplyAsync(() -> copyRemoteToLocal(session, inputs.getRemoteFile(), inputs.getLocalFile()))
                                                .get(Integer.parseInt(inputs.getConnectionTimeout()) * 1000L, TimeUnit.SECONDS);
                                    } catch (TimeoutException e) {
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 65..80

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

                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

                        switch (policy.toLowerCase(Locale.ENGLISH)) {
                            case KNOWN_HOSTS_ALLOW:
                                session.setConfig("StrictHostKeyChecking", "no");
                                break;
                            case KNOWN_HOSTS_STRICT:
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPCopier.java on lines 269..290

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

                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

                                while (true) {
                                    if (buf.length < filesize) foo = buf.length;
                                    else foo = (int) filesize;
                                    foo = in.read(buf, 0, foo);
                                    if (foo < 0) {
                cs-rft/src/main/java/io/cloudslang/content/rft/remote_copy/ScpCopier.java on lines 275..289

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

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

                            if (!StringUtils.isEmpty(inputs.getProxyHost())) {
                                ProxyHTTP proxy = new ProxyHTTP(inputs.getProxyHost(), Integer.parseInt(inputs.getProxyPort()));
                                if ((!inputs.getProxyUsername().isEmpty()) && (!inputs.getProxyPassword().isEmpty())) {
                                    proxy.setUserPasswd(inputs.getProxyUsername(), inputs.getProxyPassword());
                                }
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 54..60
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 144..150

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

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

                            if (!StringUtils.isEmpty(inputs.getProxyHost())) {
                                ProxyHTTP proxy = new ProxyHTTP(inputs.getProxyHost(), Integer.parseInt(inputs.getProxyPort()));
                                if ((!inputs.getProxyUsername().isEmpty()) && (!inputs.getProxyPassword().isEmpty())) {
                                    proxy.setUserPasswd(inputs.getProxyUsername(), inputs.getProxyPassword());
                                }
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 129..135
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 144..150

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

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

                            if (!StringUtils.isEmpty(inputs.getProxyHost())) {
                                ProxyHTTP proxy = new ProxyHTTP(inputs.getProxyHost(), Integer.parseInt(inputs.getProxyPort()));
                                if ((!inputs.getProxyUsername().isEmpty()) && (!inputs.getProxyPassword().isEmpty())) {
                                    proxy.setUserPasswd(inputs.getProxyUsername(), inputs.getProxyPassword());
                                }
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 54..60
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 129..135

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

                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

                            if (successfullyCopied) {
                                results.put(RETURN_RESULT, SUCCESS_RESULT);
                                results.put(RETURN_CODE, SUCCESS_RETURN_CODE);
                            } else {
                                results.put(RETURN_RESULT, Constants.NO_ACK_RECEIVED);
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 172..179

                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

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

                            if (successfullyCopied) {
                                results.put(RETURN_RESULT, SUCCESS_RESULT);
                                results.put(RETURN_CODE, SUCCESS_RETURN_CODE);
                            } else {
                                results.put(RETURN_RESULT, Constants.NO_ACK_RECEIVED);
                cs-rft/src/main/java/io/cloudslang/content/rft/services/SCPService.java on lines 101..108

                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

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

                        } catch (Exception e) {
                            results.put(EXCEPTION, String.valueOf(e));
                            results.put(RETURN_RESULT, (e.getMessage()));
                            results.put(RETURN_CODE, FAILURE_RETURN_CODE);
                        }
                cs-rft/src/main/java/io/cloudslang/content/rft/services/RemoteCopyService.java on lines 81..85

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

                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