File Element.java
has 569 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* Element.java
Purpose:
Description:
Element
has 61 methods (exceeds 20 allowed). Consider refactoring. Open
public class Element extends AbstractGroup
implements Attributable, Namespaceable, org.w3c.dom.Element {
/** The namespace. */
protected Namespace _ns;
/** The local name. */
Method setContent
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
public final Object setContent(Object obj) {
if (obj instanceof Item) {
getChildren().add((Item)obj);
return null; //done
}
- 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 setContent
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
public final Object setContent(Object obj) {
if (obj instanceof Item) {
getChildren().add((Item)obj);
return null; //done
}
Method removeContent
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public final Object removeContent(String path) {
Element e = this;
int j = 0;
while (true) {
int k = path.indexOf('/', 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 getContent
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public final Object getContent(String path) {
Element e = this;
int j = 0;
while (true) {
int k = path.indexOf('/', 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 setContent
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public final Object setContent(String path, Object obj) {
Element e = this;
int j = 0;
while (true) {
int k = path.indexOf('/', 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 getNamespace
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public final Namespace getNamespace(String prefix) {
if (prefix == null)
prefix = "";
Namespace ns = Namespace.getSpecial(prefix);
- 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 checkAdd
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private void checkAdd(Attribute newItem, Attribute other, boolean replace) {
//first, remove any existent with the same uri and name
if (newItem.getOwner() != null)
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
"Attribute, "+newItem.toString()+", owned by other; detach or clone it", getLocator());
- 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 hasContent
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public final boolean hasContent(String path) {
Element e = this;
int j = 0;
while (true) {
int k = path.indexOf('/', 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 setNamespace
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public final void setNamespace(Namespace ns) {
if (ns == null) {
if (_ns != null && _ns.getPrefix().length() == 0)
return; //nothing to do
ns = getNamespace("");
- 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 addDeclaredNamespace
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public final boolean addDeclaredNamespace(Namespace ns) {
if (_addNamespaces == null) {
_addNamespaces = new LinkedHashMap<String, Namespace>(4);
} else {
final Namespace old = _addNamespaces.get(ns.getPrefix());
- 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 prefix.length() > 0 ? null: Namespace.NO_NAMESPACE;
Method setNamespace
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public final void setNamespace(String prefix, String nsURI) {
if (nsURI == null) nsURI = "";
final Namespace ns = getNamespace(prefix);
if (ns != null) {
if (ns.getURI().equals(nsURI)) {
- 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 getAttributeIndex
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public final int getAttributeIndex
(int indexFrom, String namespace, String name, int mode) {
if (_attrs == null || indexFrom < 0 || indexFrom >= _attrs.size())
return -1;
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
public final void setTagName(String tname) {
int kp = tname.indexOf(':');
String prefix = kp >= 0 ? tname.substring(0, kp): "";
String lname = kp >= 0 ? tname.substring(kp + 1): tname;
setPrefix(prefix);
- 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 75.
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