Method create
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
public static GenericCreator create(IdMap map, Class<?> instance) {
if (map == null || instance == null) {
return null;
}
SendableEntityCreator creator = map.getCreator(instance.getName(), true, true, null);
- Read upRead up
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 GenericCreator.java
has 277 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.ext.generic;
/*
NetworkParser
The MIT License
Method create
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static GenericCreator create(IdMap map, Class<?> instance) {
if (map == null || instance == null) {
return null;
}
SendableEntityCreator creator = map.getCreator(instance.getName(), true, true, null);
Method setNewValue
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private boolean setNewValue(Object entity, String methodName, Object value) {
if (this.clazz == null || value == null) {
return false;
}
try {
Method getValue
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public Object getValue(Object entity, String attribute) {
if (entity == null || this.clazz == null) {
return null;
}
Method setValue
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public boolean setValue(Object entity, String attribute, Object value, String type) {
if (entity == null || this.clazz == null) {
return false;
}
Method setValue
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
@Override
public boolean setValue(Object entity, String attribute, Object value, String type) {
if (entity == null || this.clazz == null) {
return false;
}
- Read upRead up
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 setNewValue
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private boolean setNewValue(Object entity, String methodName, Object value) {
if (this.clazz == null || value == null) {
return false;
}
try {
- Read upRead up
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 getValidMethod
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
String getValidMethod(String methodName) {
String name = null;
if (methodName != null && badProperties.contains(methodName) == false) {
if (methodName.startsWith("get")) {
name = methodName.substring(3);
- Read upRead up
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 (childClass != null) {
child = ReflectionLoader.getClass("" + childClass);
}
Avoid deeply nested control flow statements. Open
if (genericSuperclass.getActualTypeArguments().length > 0) {
Type type = genericSuperclass.getActualTypeArguments()[0];
String typeClass = "" + ReflectionLoader.call(type, "getTypeName");
if (typeClass.length() > 0) {
child = Class.forName(typeClass);
Method withItem
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public GenericCreator withItem(Object value) {
this.item = value;
/* Init all Values */
if (this.item == null) {
- Read upRead up
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 false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return invoke;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return true;
Method getValue
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
@Override
public Object getValue(Object entity, String attribute) {
if (entity == null || this.clazz == null) {
return null;
}
- Read upRead up
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
These nested if statements could be combined Open
if (setNewValue(entity, "addTo" + this.getMethodName(attribute), value)) {
return true;
}
- Read upRead up
- Exclude checks
CollapsibleIfStatements
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
Example:
void bar() {
if (x) { // original implementation
if (y) {
// do stuff
}
}
}
void bar() {
if (x && y) { // optimized implementation
// do stuff
}
}