SiLeBAT/FSK-Lab

View on GitHub
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java

Summary

Maintainability
F
1 wk
Test Coverage

File RController.java has 1113 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * ------------------------------------------------------------------ Copyright by KNIME GmbH,
 * Konstanz, Germany Website: http://www.knime.org; Email: contact@knime.org
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the

Method monitoredAssign has a Cognitive Complexity of 103 (exceeds 5 allowed). Consider refactoring.
Open

  @Override
  public void monitoredAssign(final String name, final BufferedDataTable table,
      final ExecutionMonitor exec, final int batchSize, final String rType,
      final boolean sendRowNames) throws RException, CanceledExecutionException {

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

  @Override
  public BufferedDataTable importBufferedDataTable(String varName, boolean nonNumbersAsMissing,
      ExecutionContext exec) throws RException, CanceledExecutionException {

    final REXP typeRexp = eval("class(" + varName + ")", 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 monitoredAssign has 221 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  @Override
  public void monitoredAssign(final String name, final BufferedDataTable table,
      final ExecutionMonitor exec, final int batchSize, final String rType,
      final boolean sendRowNames) throws RException, CanceledExecutionException {

Method importBufferedDataTable has 168 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  @Override
  public BufferedDataTable importBufferedDataTable(String varName, boolean nonNumbersAsMissing,
      ExecutionContext exec) throws RException, CanceledExecutionException {

    final REXP typeRexp = eval("class(" + varName + ")", true);

RController has 41 methods (exceeds 20 allowed). Consider refactoring.
Open

public class RController implements IRController {

  private final NodeLogger LOGGER = NodeLogger.getLogger(getClass());

  private static final String TEMP_VARIABLE_NAME = "knimertemp836481";

Method importCells has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

  private static final void importCells(final REXP rexp, final DataCell[] column,
      final boolean nonNumbersAsMissing) throws REXPMismatchException {
    if (rexp.isLogical()) {
      final byte[] bytes = rexp.asBytes();
      for (int i = 0; i < bytes.length; ++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

Method checkCairoOnMac has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private void checkCairoOnMac() throws RException {

    if (cairoFound && quartzFound) {
      return;
    }

Method importCells has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private static final void importCells(final REXP rexp, final DataCell[] column,
      final boolean nonNumbersAsMissing) throws REXPMismatchException {
    if (rexp.isLogical()) {
      final byte[] bytes = rexp.asBytes();
      for (int i = 0; i < bytes.length; ++i) {

Method initR has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private void initR() throws RException {
    try {
      String rHome = PreferenceInitializer.getR3Provider().getRHome();

      // FIXME: Workaround for Linux server in BfR. If R home is not configure then

Method initR has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  private void initR() throws RException {
    try {
      String rHome = PreferenceInitializer.getR3Provider().getRHome();

      // FIXME: Workaround for Linux server in BfR. If R home is not configure then

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

  private void checkCairoOnMac() throws RException {

    if (cairoFound && quartzFound) {
      return;
    }

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

  @Override
  public Collection<FlowVariable> importFlowVariables(String variableName) throws RException {

    checkInitialized();
    final List<FlowVariable> flowVars = new ArrayList<>();

Method monitor has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private REXP monitor(final Callable<REXP> task)
        throws InterruptedException, RException, CanceledExecutionException {
      final FutureTask<REXP> runningTask = new FutureTask<>(task);
      final Thread t =
          (m_useNodeContext) ? ThreadUtils.threadWithContext(runningTask, "R-Evaluation")

Method importFlowVariables has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

  @Override
  public Collection<FlowVariable> importFlowVariables(String variableName) throws RException {

    checkInitialized();
    final List<FlowVariable> flowVars = new ArrayList<>();

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

  public void monitoredAssign(final String name, final BufferedDataTable table,
      final ExecutionMonitor exec, final int batchSize, final String rType,
      final boolean sendRowNames) throws RException, CanceledExecutionException {

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

  public void importDataFromPorts(final PortObject[] inData, final ExecutionMonitor exec,
      final int batchSize, final String rType, final boolean sendRowNames)

Method monitor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    private REXP monitor(final Callable<REXP> task)
        throws InterruptedException, RException, CanceledExecutionException {
      final FutureTask<REXP> runningTask = new FutureTask<>(task);
      final Thread t =
          (m_useNodeContext) ? ThreadUtils.threadWithContext(runningTask, "R-Evaluation")

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 BooleanCell.TYPE;

Avoid too many return statements within this method.
Open

      return StringCell.TYPE;

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

  private static DataType importDataType(final REXP column) {
    if (column.isNull()) {
      return StringCell.TYPE;
    } else if (column.isLogical()) {
      return BooleanCell.TYPE;

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

  public BufferedDataTable importBufferedDataTable(String varName, boolean nonNumbersAsMissing,

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

  public void monitoredAssign(final String name, final BufferedDataTable table,

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

  private static final void importCells(final REXP rexp, final DataCell[] column,

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

Add a default case to this switch.
Open

      switch (flowVar.getType()) {

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 ")<-knime.col.names" 3 times.
Open

            + name + ")<-knime.col.names", exec, false);

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.

Make the enclosing method "static" or remove this set.
Open

        cairoFound = true;

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

This rule raises an issue each time a static field is updated from a non-static method.

Noncompliant Code Example

public class MyClass {

  private static int count = 0;

  public void doSomething() {
    //...
    count++;  // Noncompliant
  }
}

Define a constant instead of duplicating this literal "load(\"" 3 times.
Open

            "load(\"" + unixPath + "\")\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.

Define a constant instead of duplicating this literal "Clearing previous workspace" 3 times.
Open

    exec.setProgress(0.0, "Clearing previous workspace");

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.

Make the enclosing method "static" or remove this set.
Open

          quartzFound = true;

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

This rule raises an issue each time a static field is updated from a non-static method.

Noncompliant Code Example

public class MyClass {

  private static int count = 0;

  public void doSomething() {
    //...
    count++;  // Noncompliant
  }
}

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

  @Override
  public void assign(final String symbol, final int value) throws RException {
    checkInitialized();
    try {
      synchronized (getREngine()) {
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 461..471

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

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

  @Override
  public void assign(final String symbol, final double value) throws RException {
    checkInitialized();
    try {
      synchronized (getREngine()) {
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 449..459

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

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

  @Override
  public void assign(final String expr, final REXP value) throws RException {
    checkInitialized();
    try {
      synchronized (getREngine()) {
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 473..483

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

  @Override
  public void assign(final String expr, final String value) throws RException {
    checkInitialized();
    try {
      synchronized (getREngine()) {
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 485..495

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

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

        if (outSpec == null || cont == null) {
          // create container and outspec for the first batch of rows
          outSpec = new DataTableSpec(colSpecs.toArray(new DataColumnSpec[colSpecs.size()]));
          cont = exec.createDataContainer(outSpec);
        }
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 854..858

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

      if (outSpec == null || cont == null) {
        // create container and outspec for the first batch of rows
        outSpec = new DataTableSpec(colSpecs.toArray(new DataColumnSpec[colSpecs.size()]));
        cont = exec.createDataContainer(outSpec);
      }
de.bund.bfr.knime.fsklab.r/src/de/bund/bfr/knime/fsklab/r/client/RController.java on lines 799..803

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

There are no issues that match your filters.

Category
Status