Method parse
has a Cognitive Complexity of 184 (exceeds 5 allowed). Consider refactoring. Open
private Object parse(RequestContext reqctx, InputStream is, String path) throws Exception {
final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
final String name = IDOMs.getRequiredAttributeValue(root, "name");
if (name.length() == 0)
throw new UiException("The name attribute must be specified, " + root.getLocator() + ", " + path);
- 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 WpdExtendlet.java
has 910 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* WpdExtendlet.java
Purpose:
Description:
Method parse
has 240 lines of code (exceeds 25 allowed). Consider refactoring. Open
private Object parse(RequestContext reqctx, InputStream is, String path) throws Exception {
final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
final String name = IDOMs.getRequiredAttributeValue(root, "name");
if (name.length() == 0)
throw new UiException("The name attribute must be specified, " + root.getLocator() + ", " + path);
Method retrieve
has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring. Open
protected byte[] retrieve(HttpServletRequest request, HttpServletResponse response, String path)
throws ServletException, IOException {
byte[] data;
String pkg = null;
boolean sourceMapEnabled = sourceMapEnabled();
- 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 retrieve
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected byte[] retrieve(HttpServletRequest request, HttpServletResponse response, String path)
throws ServletException, IOException {
byte[] data;
String pkg = null;
boolean sourceMapEnabled = sourceMapEnabled();
Method toByteArray
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
private byte[] toByteArray(RequestContext reqctx) throws ServletException, IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final HttpServletRequest request = reqctx.request;
final String main = request != null ? request.getParameter("main") : 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
Method processWpdForSourcemapIfAny
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private String processWpdForSourcemapIfAny(List<String> paths, String originalPathPrefix, String path) throws Exception {
final Content content = (Content) _cache.get(path);
if (content == null) {
log.error("Failed to load the resource: " + path);
throw new java.io.FileNotFoundException("Failed to load the resource: " + path);
- 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
WpdExtendlet
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
public class WpdExtendlet extends AbstractExtendlet<Object> {
//source map
public static final String SOURCE_MAP_JAVASCRIPT_PATH = "$zk$sourcemapJsPath"; // for HtmlPageRenders
private static final String SOURCE_MAP_DIVIDED_WPDS = "$zk$dividedWPDs";
private static final String SOURCE_MAP_DIVIDED_WPDS_NUMBER = "$zk$dividedWPDsNum";
Method writeAppInfo
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void writeAppInfo(RequestContext reqctx, OutputStream out, WebApp wapp) throws IOException, ServletException {
final String verInfoEnabled = Library.getProperty("org.zkoss.zk.ui.versionInfo.enabled", "true");
final boolean exposeVer = "true".equals(verInfoEnabled);
final StringBuffer sb = new StringBuffer(256);
if (exposeVer)
Method processWpdForSourcemapIfAny
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String processWpdForSourcemapIfAny(List<String> paths, String originalPathPrefix, String path) throws Exception {
final Content content = (Content) _cache.get(path);
if (content == null) {
log.error("Failed to load the resource: " + path);
throw new java.io.FileNotFoundException("Failed to load the resource: " + path);
Method writeAppInfo
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private void writeAppInfo(RequestContext reqctx, OutputStream out, WebApp wapp) throws IOException, ServletException {
final String verInfoEnabled = Library.getProperty("org.zkoss.zk.ui.versionInfo.enabled", "true");
final boolean exposeVer = "true".equals(verInfoEnabled);
final StringBuffer sb = new StringBuffer(256);
if (exposeVer)
- 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 findResourcePath
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
if (path.startsWith("~./")) path = path.substring(2);
else if (path.charAt(0) != '/') path = Files.normalize(dir, path);
//source map browser issue and check source map file is available or not
String originalPath = "";
- 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 toByteArray
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
@SuppressWarnings("unchecked")
private byte[] toByteArray(RequestContext reqctx) throws ServletException, IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final HttpServletRequest request = reqctx.request;
final String main = request != null ? request.getParameter("main") : null;
Method processDynamicWpdWithSourceMapIfAny
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private byte[] processDynamicWpdWithSourceMapIfAny(HttpServletRequest request, HttpServletResponse response, String pkgWpd, String path) throws Exception {
List<String> dividedPaths = splitSourceMapJsPathIfAny(path);
StringBuilder sb = new StringBuilder();
int index = 0;
String lastWpd = null;
Method findResourcePath
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
if (path.startsWith("~./")) path = path.substring(2);
else if (path.charAt(0) != '/') path = Files.normalize(dir, path);
//source map browser issue and check source map file is available or not
String originalPath = "";
Method mergeJavaScript
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected byte[] mergeJavaScript(HttpServletRequest request, HttpServletResponse response, String pkgTo,
byte[] data) throws ServletException, IOException {
ByteArrayOutputStream out = null;
Device device = null;
final String deviceType = getDeviceType();
- 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 parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private Object parse(RequestContext reqctx) throws ServletException, IOException {
if (_cnt instanceof SourceInfo)
try {
_cnt = ((SourceInfo) _cnt).parse(reqctx);
} catch (IOException ex) {
- 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 findResourcePath
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
Method outErrReloads
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private void outErrReloads(RequestContext reqctx, Configuration config, StringBuffer sb, Object[][] infs) {
for (int j = 0; j < infs.length; ++j) {
if (j > 0)
sb.append(',');
sb.append('\'').append(infs[j][0]).append("':'");
- 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 writeResource
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private boolean writeResource(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate) throws IOException, ServletException {
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
if (isNotModified) return null;
Avoid too many return
statements within this method. Open
return ("(function(){zk.setLoaded('" + lastPart.replace("$.wpd", "") + "');})()").getBytes();
Avoid too many return
statements within this method. Open
return ("(function(){zk._p=zkpi('" + pkgName + "');})()").getBytes();
Avoid too many return
statements within this method. Open
return pkg != null && !sourceMapEnabled ? mergeJavaScript(request, response, pkg, data) : data;
Method processDynamicWpdWithSourceMapIfAny
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private byte[] processDynamicWpdWithSourceMapIfAny(HttpServletRequest request, HttpServletResponse response, String pkgWpd, String path) throws Exception {
List<String> dividedPaths = splitSourceMapJsPathIfAny(path);
StringBuilder sb = new StringBuilder();
int index = 0;
String lastWpd = 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
Method isWpdContentRequired
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private boolean isWpdContentRequired(String pkg, Element root) {
for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(getDeviceType()))
if (langdef.getJavaScriptPackagesWithMerges().contains(pkg)) return true;
for (Iterator it = root.getElements("script").iterator(); it.hasNext();) {
- 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 2 locations. Consider refactoring. Open
if (_webctx.shallCompress(request, "wpd") && data.length > 200) {
byte[] bs = Https.gzip(request, response, null, data);
if (bs != null)
data = bs; //yes, browser support compress
}
- 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 56.
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