SiLeBAT/FSK-Lab

View on GitHub
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/custom/MyProzessXMLImporter.java

Summary

Maintainability
F
1 wk
Test Coverage

Method doImport has a Cognitive Complexity of 110 (exceeds 5 allowed). Consider refactoring.
Open

        public String doImport(final String filename, final JProgressBar progress, final boolean showResults) {
            errorMessage = "";
          Runnable runnable = new Runnable() {
          public void run() {
            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 run has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
Open

          public void run() {
            try {
                MyLogger.handleMessage("Importing PEX-File: " + filename);
                  if (progress != null) {
                      progress.setVisible(true);

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

        public String doImport(final String filename, final JProgressBar progress, final boolean showResults) {
            errorMessage = "";
          Runnable runnable = new Runnable() {
          public void run() {
            try {

Method getReihenfolge has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

        private Vector<Integer> getReihenfolge(Vector<Integer[]> org_dst) {
            Vector<Integer> indexReihenfolge = new Vector<>();
            Integer[] int2 = org_dst.get(0);
            int[] valsA = new int[2];
            int[] valsE = new int[2];

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 MyProzessXMLImporter.java has 366 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*******************************************************************************
 * Copyright (c) 2015 Federal Institute for Risk Assessment (BfR), Germany
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by

Method getReihenfolgePrev has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

        private int getReihenfolgePrev(Vector<Integer[]> org_dst, Vector<Integer> indexReihenfolge) {
            int wegPfeile = 0; // Ein Knoten kann mehrere Pfeile haben, die ihn verlassen ..., z.B. Salami_Test_Britta, gleich der erste Knoten "Wareneingang" führt zum einen zu "Speck (Meat, Raw)" zum anderen zu "Schweinefleich , roh (Meat, Raw)"
            if (indexReihenfolge != null) {
                Vector<Vector<Integer>> rhflgn = new Vector<>();
                int firstIndex = indexReihenfolge.get(0);

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

        private void cleanReihenfolgeListe(Vector<Integer> indexReihenfolge, LinkedHashMap<Integer, Integer> index_processID, Vector<Integer[]> org_dst) {
            for (int ii=0;ii<indexReihenfolge.size();ii++) {
                Integer key = indexReihenfolge.get(ii);
                Integer carverID = index_processID.get(key);
                //System.out.println(key + "\t" + carverID + "\t" + isBlacklisted(carverID));

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

        private Vector<Integer> getReihenfolge(Vector<Integer[]> org_dst) {
            Vector<Integer> indexReihenfolge = new Vector<>();
            Integer[] int2 = org_dst.get(0);
            int[] valsA = new int[2];
            int[] valsE = new int[2];

Consider simplifying this complex logical expression.
Open

            if (carverID >= 1 && carverID <= 31 || carverID == 332 ||
                    carverID >= 217 && carverID <= 220 ||
                    carverID >= 295 && carverID <= 307 ||
                    carverID >= 338 && carverID <= 340) result = true; // Material
            else if (carverID >= 280 && carverID <= 290 || carverID == 342) result = true; // Verpackung

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

        private int getReihenfolgePrev(Vector<Integer[]> org_dst, Vector<Integer> indexReihenfolge) {
            int wegPfeile = 0; // Ein Knoten kann mehrere Pfeile haben, die ihn verlassen ..., z.B. Salami_Test_Britta, gleich der erste Knoten "Wareneingang" führt zum einen zu "Speck (Meat, Raw)" zum anderen zu "Schweinefleich , roh (Meat, Raw)"
            if (indexReihenfolge != null) {
                Vector<Vector<Integer>> rhflgn = new Vector<>();
                int firstIndex = indexReihenfolge.get(0);

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

        private boolean isBlacklisted(int carverID) {
            boolean result = false;
            if (carverID >= 1 && carverID <= 31 || carverID == 332 ||
                    carverID >= 217 && carverID <= 220 ||
                    carverID >= 295 && carverID <= 307 ||

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 (int2[0] == indexReihenfolge.get(ii)) {
                                        psmt.clearParameters();
                                        psmt.setInt(1, index_ProzessdatenID.get(int2[0]));
                                        Integer pid = index_ProzessdatenID.get(int2[1]);
                                        if (pid != null) {

Avoid deeply nested control flow statements.
Open

                            for (int iii=0;iii<org_dst.size();iii++) {
                                Integer[] int22 = org_dst.get(iii);
                                if (int22[0] == int2[1]) {
                                    org_dst.add(new Integer[]{int2[0],int22[1]});
                                }

Avoid deeply nested control flow statements.
Open

                                    if (rs.next()) {
                                        if (i==0) DBKernel.insertBLOB("Prozessdaten", "Workflow", xmlFile, rs.getInt(1));
                                        index_ProzessdatenID.put(key, rs.getInt(1));
                                        importedCarverIDs.add(value);
                                    }

Avoid deeply nested control flow statements.
Open

                            if (indexReihenfolgeNewEnde.get(j) == indexReihenfolge.get(k)) {
                                if (k == indexReihenfolge.size()-1) errorMessage += "Ups, 2.Ende... hier ist was schiefgelaufen!\nBitte die Carver Datei (*.pex,*.xml) an Armin senden!\n";
                                System.err.println(indexReihenfolgeNewEnde.get(j));
                                
                                for (int l=1;j+l < indexReihenfolgeNewEnde.size();l++) {

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

        private void findEnde(Vector<Integer[]> org_dst, int aktuell, int step, int[] vals, boolean anfang) {            

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

        private void findEnde(Vector<Integer[]> org_dst, int aktuell, int step, int[] vals, boolean anfang) {            
            Integer[] int2;
            boolean found = false;
            for (int i=0;i<org_dst.size();i++) {
                int2 = org_dst.get(i);

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

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

        private void cleanReihenfolgeListe(Vector<Integer> indexReihenfolge, LinkedHashMap<Integer, Integer> index_processID, Vector<Integer[]> org_dst) {

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 111 to the 15 allowed.
Open

        public String doImport(final String filename, final JProgressBar progress, final boolean showResults) {

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 29 to the 15 allowed.
Open

        private int getReihenfolgePrev(Vector<Integer[]> org_dst, Vector<Integer> indexReihenfolge) {

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 44 to the 15 allowed.
Open

        private Vector<Integer> getReihenfolge(Vector<Integer[]> org_dst) {

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 "INSERT INTO " 3 times.
Open

                        String sql = "INSERT INTO " + DBKernel.delimitL("ProzessWorkflow") +

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.

Define a constant instead of duplicating this literal "ProzessWorkflow" 4 times.
Open

                        String sql = "INSERT INTO " + DBKernel.delimitL("ProzessWorkflow") +

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.

Define a constant instead of duplicating this literal "Prozessdaten" 4 times.
Open

                            sql = "INSERT INTO " + DBKernel.delimitL("Prozessdaten") +

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.

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

        private String getExtension(File f) {
          String s = f.getName();
          int i = s.lastIndexOf('.');
          if (i > 0 &&  i < s.length() - 1) return s.substring(i+1).toLowerCase();
          return "";
org.hsh.bfr.db/src/org/hsh/bfr/db/exports/ExcelExport.java on lines 67..72
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/GeneralXLSImporter.java on lines 92..97
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/custom/LieferkettenImporterEFSA.java on lines 155..160
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/custom/MyRisImporter.java on lines 82..87

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

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

                  if (progress != null) {
                      progress.setVisible(true);
                      progress.setStringPainted(true);
                      progress.setString("Importiere Carver-Datei...");
                      progress.setMinimum(0);
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/GeneralXLSImporter.java on lines 103..108
org.hsh.bfr.db/src/org/hsh/bfr/db/imports/custom/LieferkettenImporterEFSA.java on lines 1188..1193

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