Method parseAction
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
private static int parseAction(Context ctx, Node parent, String prefix, int from, int to)
throws DspException, IOException, XelException {
//1: which action
int j = skipWhitespaces(ctx, from + 1, to);
int k = nextSeparator(ctx, j, to);
- 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 Parser.java
has 445 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* Parser.java
Purpose:
Description:
Method parse0
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
private static void parse0(Context ctx, Node parent, int from, int to)
throws DspException, IOException, XelException {
boolean esc = false;
final StringBuffer sb = new StringBuffer(512);
for (int j = from; j < to; ++j) {
- 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 parseAttrs
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
private static int parseAttrs(Context ctx, Map<String, String> attrs, String actnm, int from, int to)
throws DspException {
for (int j, k = from;;) {
j = skipWhitespaces(ctx, k, to);
k = nextSeparator(ctx, j, to);
- 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 parseControl
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
private static int parseControl(Context ctx, Node parent, int from, int to)
throws DspException, IOException, XelException {
int j = from + 2;
if (j + 1 >= to)
throw new DspException(MWeb.DSP_ACTION_NOT_TERMINATED, new Object[] { null, new Integer(ctx.nLines) });
- 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 endOfEL
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
private static int endOfEL(Context ctx, int from, int to) throws DspException {
for (int j = from + 2;; ++j) {
if (j >= to)
throw new DspException(MWeb.EL_NOT_TERMINATED, new Integer(ctx.nLines));
- 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 parseAction
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int parseAction(Context ctx, Node parent, String prefix, int from, int to)
throws DspException, IOException, XelException {
//1: which action
int j = skipWhitespaces(ctx, from + 1, to);
int k = nextSeparator(ctx, j, to);
Method parse0
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static void parse0(Context ctx, Node parent, int from, int to)
throws DspException, IOException, XelException {
boolean esc = false;
final StringBuffer sb = new StringBuffer(512);
for (int j = from; j < to; ++j) {
Method parseControl
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int parseControl(Context ctx, Node parent, int from, int to)
throws DspException, IOException, XelException {
int j = from + 2;
if (j + 1 >= to)
throw new DspException(MWeb.DSP_ACTION_NOT_TERMINATED, new Object[] { null, new Integer(ctx.nLines) });
Method parseAttrs
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int parseAttrs(Context ctx, Map<String, String> attrs, String actnm, int from, int to)
throws DspException {
for (int j, k = from;;) {
j = skipWhitespaces(ctx, k, to);
k = nextSeparator(ctx, j, to);
Consider simplifying this complex logical expression. Open
if ((cc < '0' || cc > '9') && (cc < 'a' || cc > 'z') && (cc < 'A' || cc > 'Z') && cc != '_')
break;
Avoid deeply nested control flow statements. Open
if (j + 2 < to && ctx.content.charAt(j + 2) == '{')
++j; //skip '\\'
Avoid deeply nested control flow statements. Open
if (j + 2 < to && ctx.content.charAt(j + 2) == '%')
++j; //skip '\\'
Avoid deeply nested control flow statements. Open
if (--depth < 0) {
nestedTo = j;
j = l;
break; //done
}
Method parseAction
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int parseAction(Context ctx, Node parent, String prefix, int from, int to)
Method parseAttrs
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int parseAttrs(Context ctx, Map<String, String> attrs, String actnm, int from, int to)
Method nextSeparator
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static int nextSeparator(Context ctx, int from, int to) {
for (; from < to; ++from) {
final char cc = ctx.content.charAt(from);
if ((cc < '0' || cc > '9') && (cc < 'a' || cc > 'z') && (cc < 'A' || cc > 'Z') && cc != '_')
break;
- 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 trim
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static void trim(Node node) {
for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
final Object o = it.next();
if (o instanceof TextNode) {
final String s = ((TextNode) o).getText();
- 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 loadTaglib
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private void loadTaglib(String prefix, String uri) throws DspException, IOException {
if (_locator == null)
throw new DspException("Unable to load " + uri + " because locator is not specified");
URL url = uri.indexOf("://") > 0 ? null : _locator.getResource(uri);
- 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 startsWith
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static boolean startsWith(String content, int from, int to, String s) {
for (int j = 0, len = s.length();; ++from, ++j) {
if (j >= len)
return true;
if (from >= to || content.charAt(from) != s.charAt(j))
- 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
Similar blocks of code found in 4 locations. Consider refactoring. Open
if ((cc < '0' || cc > '9') && (cc < 'a' || cc > 'z') && (cc < 'A' || cc > 'Z') && cc != '_')
- 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