zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java

Summary

Maintainability
F
4 days
Test Coverage

File ClassWebResource.java has 527 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* ClassWebResource.java

    Purpose:
        
    Description:
Severity: Major
Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 1 day to fix

    Method web0 has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

        private void web0(HttpServletRequest request, HttpServletResponse response, String pi, String ext)
                throws ServletException, IOException {
            if (ext != null) {
                //Invoke the resource processor (Extendlet)
                final Extendlet extlet = getExtendlet(ext);
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 7 hrs to fix

    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

    ClassWebResource has 36 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class ClassWebResource {
        private static final Logger log = LoggerFactory.getLogger(ClassWebResource.class);
    
        private final ServletContext _ctx;
        /** mapping URI including PATH_PREFIX. */
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 4 hrs to fix

      Method web0 has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private void web0(HttpServletRequest request, HttpServletResponse response, String pi, String ext)
                  throws ServletException, IOException {
              if (ext != null) {
                  //Invoke the resource processor (Extendlet)
                  final Extendlet extlet = getExtendlet(ext);
      Severity: Major
      Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 3 hrs to fix

        Method encodeURL has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                public String encodeURL(ServletRequest request, ServletResponse response, String uri)
                        throws ServletException, UnsupportedEncodingException {
                    uri = Servlets.locate(_ctx, request, uri, getLocator()); //resolves "*"
                    uri = (_encURLPrefix != null ? _mappingURI + _encURLPrefix : _mappingURI) + uri; //prefix with mapping
        
        

        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 encodeURL has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public String encodeURL(ServletRequest request, ServletResponse response, String uri)
                        throws ServletException, UnsupportedEncodingException {
                    uri = Servlets.locate(_ctx, request, uri, getLocator()); //resolves "*"
                    uri = (_encURLPrefix != null ? _mappingURI + _encURLPrefix : _mappingURI) + uri; //prefix with mapping
        
        

          Method getFilters has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public Filter[] getFilters(String ext, int flag) {
                  if (ext == null)
                      return null;
          
                  ext = ext.toLowerCase(java.util.Locale.ENGLISH);
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 55 mins to fix

          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 modifyPath has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public String modifyPath(String path) throws UnsupportedEncodingException {
                  if (path.startsWith(ZVER)) {
                      final int j = path.indexOf('/', ZVER.length());
                      if (j >= 0)
                          path = path.substring(j);
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 45 mins to fix

          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 encodeRedirectURL has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  public String encodeRedirectURL(HttpServletRequest request, HttpServletResponse response, String uri,
                          Map params, int mode) {
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 35 mins to fix

            Method getExtendlet has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public Extendlet getExtendlet(String ext, boolean lookup) {
                    if (ext == null)
                        return null;
            
                    ext = ext.toLowerCase(java.util.Locale.ENGLISH);
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 35 mins to fix

            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 addFilter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public void addFilter(String ext, Filter filter, int flags) {
                    if (ext == null || filter == null)
                        throw new IllegalArgumentException("null");
            
                    filter.init(new FilterConfig() {
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 35 mins to fix

            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 rmFilter has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                private static boolean rmFilter(Map<String, FastReadArray<Filter>> filters, String ext, Filter filter) {
                    FastReadArray<Filter> ary = filters.get(ext);
                    if (ary != null && ary.remove(filter)) {
                        if (ary.isEmpty())
                            ary = filters.remove(ext);
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 35 mins to fix

            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 include has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                    public void include(HttpServletRequest request, HttpServletResponse response, String uri, Map params)
                            throws ServletException, IOException {
                        //Note: it is caller's job to convert related path to ~./
                        if (uri.startsWith("~./") && uri.indexOf('?') < 0 && isDirectInclude(uri)) {
                            Object old = request.getAttribute(Attributes.ARG);
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 25 mins to fix

            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 getResourceAsStream has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public InputStream getResourceAsStream(String uri) {
                    uri = fixURI(uri);
                    if (_extraloc != null) {
                        final InputStream is = _extraloc.getResourceAsStream(uri);
                        if (is != null)
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 25 mins to fix

            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 removeFilter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public boolean removeFilter(String ext, Filter filter, int flags) {
                    if (ext == null || filter == null)
                        return false;
            
                    ext = ext.toLowerCase(java.util.Locale.ENGLISH);
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 25 mins to fix

            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 getResource has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public URL getResource(String uri) {
                    uri = fixURI(uri);
                    if (_extraloc != null) {
                        final URL url = _extraloc.getResource(uri);
                        if (url != null)
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java - About 25 mins to fix

            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

                public URL getResource(String uri) {
                    uri = fixURI(uri);
                    if (_extraloc != null) {
                        final URL url = _extraloc.getResource(uri);
                        if (url != null)
            zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java on lines 167..181

            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 114.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public InputStream getResourceAsStream(String uri) {
                    uri = fixURI(uri);
                    if (_extraloc != null) {
                        final InputStream is = _extraloc.getResourceAsStream(uri);
                        if (is != null)
            zweb/src/main/java/org/zkoss/web/util/resource/ClassWebResource.java on lines 147..160

            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 114.

            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

            Further Reading

            There are no issues that match your filters.

            Category
            Status