deeplearning4j/deeplearning4j

View on GitHub
codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/DocsGenerator.java

Summary

Maintainability
F
3 days
Test Coverage

Method generateDocs has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
Open

    public static void generateDocs(int namespaceNum, NamespaceOps namespace, String docsDirectory, String basePackage) throws IOException {
        File outputDirectory = new File(docsDirectory);
        StringBuilder sb = new StringBuilder();
        String headerName = namespace.getName();
        if(headerName.startsWith("SD"))

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 generateDocs has 114 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static void generateDocs(int namespaceNum, NamespaceOps namespace, String docsDirectory, String basePackage) throws IOException {
        File outputDirectory = new File(docsDirectory);
        StringBuilder sb = new StringBuilder();
        String headerName = namespace.getName();
        if(headerName.startsWith("SD"))

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

        private static String generateMethodText(Op op, Signature s, boolean isSameDiff, boolean isLoss, boolean withName) {
            StringBuilder sb = new StringBuilder();
            MethodSpec.Builder c = MethodSpec.methodBuilder(GenUtil.ensureFirstIsNotCap(op.getOpName()));
            List<Parameter> params = s.getParameters();
            List<Output> outs = op.getOutputs();

    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 generateMethodText has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static String generateMethodText(Op op, Signature s, boolean isSameDiff, boolean isLoss, boolean withName) {
            StringBuilder sb = new StringBuilder();
            MethodSpec.Builder c = MethodSpec.methodBuilder(GenUtil.ensureFirstIsNotCap(op.getOpName()));
            List<Parameter> params = s.getParameters();
            List<Output> outs = op.getOutputs();

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

          private static String formatDefaultValue(Object v){
              if(v == null){ return "null"; }
              else if(v instanceof int[]){ return Arrays.toString((int[]) v); }
              else if(v instanceof long[]){ return Arrays.toString((long[]) v); }
              else if(v instanceof float[]){ return Arrays.toString((float[]) v); }

      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(p instanceof Input){
                                  Input i = (Input)p;
                                  sb.append("* **").append(i.getName()).append("** ").append(" (").append(i.getType()).append(") - ").append(i.getDescription() == null ? "" : DocTokens.processDocText(i.getDescription(),
                                          op, DocTokens.GenerationType.ND4J)).append(System.lineSeparator());
                              }

        Avoid deeply nested control flow statements.
        Open

                                if(alreadySeen.contains(p)) continue;

          Method generateMethodText has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              private static String generateMethodText(Op op, Signature s, boolean isSameDiff, boolean isLoss, boolean withName) {

            Avoid too many return statements within this method.
            Open

                    else if(v instanceof boolean[]){ return Arrays.toString((boolean[]) v); }

              Avoid too many return statements within this method.
              Open

                      else if(v instanceof int[]){ return Arrays.toString((int[]) v); }

                Avoid too many return statements within this method.
                Open

                        else if(v instanceof long[]){ return Arrays.toString((long[]) v); }

                  Avoid too many return statements within this method.
                  Open

                          else if(v instanceof float[]){ return Arrays.toString((float[]) v); }

                    Avoid too many return statements within this method.
                    Open

                            if(v == null){ return "null"; }

                      Avoid too many return statements within this method.
                      Open

                              else if(v instanceof double[]){ return Arrays.toString((double[]) v); }

                        Method buildDocSectionText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private static StringBuilder buildDocSectionText(List<DocSection> docSections) {
                                StringBuilder sb = new StringBuilder();
                                for (DocSection ds : docSections) {
                                    //if(ds.applies(Language.JAVA, CodeComponent.OP_CREATOR)){
                                    String text = ds.getText();

                        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

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

                                if (outs.size() == 1) {
                                    retType = isSameDiff ? "SDVariable" : "INDArray";
                                }
                                else if (outs.size() >= 1) {
                                    retType = isSameDiff ? "SDVariable[]" : "INDArray[]";
                        codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/Nd4jNamespaceGenerator.java on lines 601..606

                        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

                                        if (i.hasDefaultValue() && (i.defaultValue() != null))
                                            sb.append(" Default value:").append(formatDefaultValue(i.defaultValue())).append(System.lineSeparator());
                                        else
                                            sb.append(System.lineSeparator());
                        codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/DocsGenerator.java on lines 251..254

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

                        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

                                        if (arg.hasDefaultValue() && (arg.defaultValue() != null))
                                            sb.append(" - default = ").append(formatDefaultValue(arg.defaultValue())).append(System.lineSeparator());
                                        else
                                            sb.append(System.lineSeparator());
                        codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/DocsGenerator.java on lines 244..247

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

                        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

                                                        sb.append("* **").append(arg.getName()).append("** - ").append(arg.getDescription() == null ? "" : DocTokens.processDocText(arg.getDescription(),
                                                                op, DocTokens.GenerationType.ND4J)).append(" (Size: ").append(count.toString()).append(")");    //.append(System.lineSeparator());
                        codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/DocsGenerator.java on lines 217..218

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

                        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

                                                        sb.append("* **").append(arg.getName()).append("** - ").append(arg.getDescription() == null ? "" : DocTokens.processDocText(arg.getDescription(),
                                                                op, DocTokens.GenerationType.ND4J));    //.append(System.lineSeparator());
                        codegen/op-codegen/src/main/java/org/nd4j/codegen/impl/java/DocsGenerator.java on lines 220..221

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

                        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