de.bund.bfr.knime.foodprocess/src/de/bund/bfr/knime/foodprocess/lib/ParametersSetting.java
ParametersSetting
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
Open
public class ParametersSetting {
private final String PARAM_TEMPERATURE = "temperature";
private final String PARAM_TEMPERATUREALT = "temperatureAlt";
private final String PARAM_TEMPERATURE_UNIT = "temperatureUnit";
private final String PARAM_VOLUME = "volume";
- Create a ticketCreate a ticket
Method saveSettings
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public void saveSettings( final Config config ) {
if (volume != null) {
config.addString( PARAM_VOLUME, volume );
}
config.addString(PARAM_VOLUME_UNIT, volumeUnit);
- Create a ticketCreate a ticket
Method loadSettings
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
public void loadSettings( final Config config ) throws InvalidSettingsException {
volume = config.containsKey(PARAM_VOLUME) ? config.getString( PARAM_VOLUME ) : null;
volumeUnit = config.getString(PARAM_VOLUME_UNIT);
temperature = config.containsKey(PARAM_TEMPERATURE) ? config.getString( PARAM_TEMPERATURE ) : null;
tempAlt = config.containsKey(PARAM_TEMPERATUREALT) ? config.getString( PARAM_TEMPERATUREALT ) : null;
- Read upRead up
- Create a ticketCreate a ticket
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 saveSettings
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
public void saveSettings( final Config config ) {
if (volume != null) {
config.addString( PARAM_VOLUME, volume );
}
config.addString(PARAM_VOLUME_UNIT, volumeUnit);
- Read upRead up
- Create a ticketCreate a ticket
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
Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation. Open
Open
public ParametersSetting() {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
There are several reasons for a method not to have a method body:
- It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
- It is not yet, or never will be, supported. In this case an
UnsupportedOperationException
should be thrown. - The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
Noncompliant Code Example
public void doSomething() { } public void doSomethingElse() { }
Compliant Solution
@Override public void doSomething() { // Do nothing because of X and Y. } @Override public void doSomethingElse() { throw new UnsupportedOperationException(); }
Exceptions
Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.
public abstract class Animal { void speak() { // default implementation ignored } }