Method getElement
has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring. Open
private Object getElement(CharacterBuffer request, CharacterBuffer path, CharacterBuffer listID,
boolean lastElement) {
int pos = 0;
SendableEntityCreator creator = this.creator;
- 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 run
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
@Override
public void run() {
try {
if (port == 0) {
return;
- 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 RESTServiceTask.java
has 364 lines of code (exceeds 250 allowed). Consider refactoring. Open
package de.uniks.networkparser.ext;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Collection;
Method getElement
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
private Object getElement(CharacterBuffer request, CharacterBuffer path, CharacterBuffer listID,
boolean lastElement) {
int pos = 0;
SendableEntityCreator creator = this.creator;
Method run
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
@Override
public void run() {
try {
if (port == 0) {
return;
Method postExecute
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String postExecute(SimpleEvent socketRequest) {
if (socketRequest == null) {
return HTTPRequest.HTTP__NOTFOUND;
}
Object source = socketRequest.getSource();
Method getExecute
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private String getExecute(SimpleEvent socketRequest) {
CharacterBuffer path = new CharacterBuffer();
CharacterBuffer listID = new CharacterBuffer();
CharacterBuffer request = new CharacterBuffer().with(socketRequest.getPropertyName());
Object element = getElement(request, path, listID, 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 getExecute
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String getExecute(SimpleEvent socketRequest) {
CharacterBuffer path = new CharacterBuffer();
CharacterBuffer listID = new CharacterBuffer();
CharacterBuffer request = new CharacterBuffer().with(socketRequest.getPropertyName());
Object element = getElement(request, path, listID, false);
Method postExecute
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private String postExecute(SimpleEvent socketRequest) {
if (socketRequest == null) {
return HTTPRequest.HTTP__NOTFOUND;
}
Object source = socketRequest.getSource();
- 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 (id.length() > 0) {
element = null;
while (i.hasNext()) {
item = i.next();
if (id.equals(map.getId(item, true))) {
Method executeRequest
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public String executeRequest(SimpleEvent socketRequest) {
if (socketRequest == null) {
return null;
}
String type = socketRequest.getType();
- 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 this.patchExecute(socketRequest);
Avoid too many return
statements within this method. Open
return this.deleteExecute(socketRequest);
Avoid too many return
statements within this method. Open
return null;
Method stop
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public void stop() {
if (serverSocket != null) {
try {
ServerSocket socket = serverSocket;
serverSocket = 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 (loginController.update(event) == false) {
clientSocket.close();
continue;
}
- 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
}
}