Showing 16 of 16 total issues
Method explore
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
private void explore(Route route, Object object, Trace trace) {
for (Field field : object.getClass().getDeclaredFields()) {
if (visitable(field)) {
trace.add(field);
VisitationResult visitationResult = visitor.visit(object, field);
- 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 visit
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private void visit(Object location) {
while (legIterator.hasNext()) {
Leg leg = legIterator.next();
switch (leg.getType()) {
case ITERATE_OVER_ARRAY:
- 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 explore
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void explore(Route route, Object object, Trace trace) {
for (Field field : object.getClass().getDeclaredFields()) {
if (visitable(field)) {
trace.add(field);
VisitationResult visitationResult = visitor.visit(object, field);
Method createObjectFor
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private CreationResult createObjectFor(Field field) {
Object fieldValue = null;
Class elementClass = null;
// TODO gleissc Obtain from configuration
int collectionSize = 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
Method visit
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void visit(Object location) {
while (legIterator.hasNext()) {
Leg leg = legIterator.next();
switch (leg.getType()) {
case ITERATE_OVER_ARRAY:
Method createObjectFor
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private CreationResult createObjectFor(Field field) {
Object fieldValue = null;
Class elementClass = null;
// TODO gleissc Obtain from configuration
int collectionSize = 3;
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else if (fieldValue.getClass().isArray()) {
route.addLeg(visitationResult.getFieldContext(), LegType.ITERATE_OVER_ARRAY);
int elementIndex = 0;
for (Object fieldElement : (Object[]) fieldValue) {
explore(route, fieldElement, trace.add(field, elementIndex++));
- Read upRead up
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 60.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (fieldValue instanceof Collection) {
route.addLeg(visitationResult.getFieldContext(), LegType.ITERATE_OVER_COLLECTION);
int elementIndex = 0;
for (Object fieldElement : (Collection) fieldValue) {
explore(route, fieldElement, trace.add(field, elementIndex++));
- Read upRead up
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 60.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method addLeg
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public void addLeg(FieldContext fieldContext, LegType legType) {
if (LegType.RETURN.equals(legType)) {
legs.add(Leg.RETURN_LEG);
} else {
// following code tries to avoid creating a new instance of Leg when it's not necessary.
- 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 equals
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- 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 (fieldValue instanceof Collection) {
route.addLeg(visitationResult.getFieldContext(), LegType.ITERATE_OVER_COLLECTION);
int elementIndex = 0;
for (Object fieldElement : (Collection) fieldValue) {
explore(route, fieldElement, trace.add(field, elementIndex++));
Method getFieldValue
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private Object getFieldValue(Object object, final Field field) {
Object fieldValue = null;
if (object != null) {
final boolean wasAccessible = field.isAccessible();
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 createProducers
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public List<Producer<T>> createProducers(Class<T> type, Config config, Route route, int numberOfInstances) {
List<Producer<T>> producers = new ArrayList<Producer<T>>();
ProducerVisitorContext producerVisitorContext = new ProducerVisitorContext(config);
ProducerVisitor visitor = new ProducerVisitor(producerVisitorContext);
- 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 true;
Method equals
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Value value = (Value) o;
- 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"