Method printCompareLink
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
void printCompareLink(String currentRef, String lastRef, boolean isBranch) {
if (baseUrl == null) {
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
When instantiating a SimpleDateFormat object, specify a Locale Open
dateFormatter = new SimpleDateFormat(dateFormat);
- Read upRead up
- Exclude checks
SimpleDateFormatNeedsLocale
Since: PMD 2.0
Priority: Medium
Categories: Style
Remediation Points: 50000
Be sure to specify a Locale when creating SimpleDateFormat instances to ensure that locale-appropriate formatting is used.
Example:
public class Foo {
// Should specify Locale.US (or whatever)
private SimpleDateFormat sdf = new SimpleDateFormat('pattern');
}
Prefer StringBuilder (non-synchronized) or StringBuffer (synchronized) over += for concatenating strings Open
url += String.format("/commits/%s", currentRef);
- Read upRead up
- Exclude checks
UseStringBufferForStringAppends
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
The use of the '+=' operator for appending strings causes the JVM to create and use an internal StringBuffer. If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or threadsafe StringBuffer is recommended to avoid this.
Example:
public class Foo {
void bar() {
String a;
a = 'foo';
a += ' bar';
// better would be:
// StringBuilder a = new StringBuilder('foo');
// a.append(' bar');
}
}
Prefer StringBuilder (non-synchronized) or StringBuffer (synchronized) over += for concatenating strings Open
url += String.format("/compare/%s...%s", currentRef, lastRef);
- Read upRead up
- Exclude checks
UseStringBufferForStringAppends
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
The use of the '+=' operator for appending strings causes the JVM to create and use an internal StringBuffer. If a non-trivial number of these concatenations are being used then the explicit use of a StringBuilder or threadsafe StringBuffer is recommended to avoid this.
Example:
public class Foo {
void bar() {
String a;
a = 'foo';
a += ' bar';
// better would be:
// StringBuilder a = new StringBuilder('foo');
// a.append(' bar');
}
}