zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java

Summary

Maintainability
F
5 days
Test Coverage

Method grad has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

    private static String grad(String dir, Browser template, String[] colors) {
        if ("|ver|hor|diag-|diag+|rad|".indexOf("|" + dir + "|") == -1)
            throw new IllegalArgumentException("Type must be ver, hor, diag-, diag+, or rad.");
        if (colors.length < 2)
            throw new IllegalArgumentException("Please specify more than two colors.");
Severity: Minor
Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 6 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

Method getBrowser has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    private static Browser getBrowser() {
        Double number = Servlets.getBrowser(ServletFns.getCurrentRequest(), "ff");
        if (number != null && number >= 3.6)
            return Browser.Firefox;
        number = Servlets.getBrowser(ServletFns.getCurrentRequest(), "ie");
Severity: Minor
Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 5 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

File ThemeFns.java has 376 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* ThemeFns.java

{{IS_NOTE
    Purpose:
        
Severity: Minor
Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 5 hrs to fix

    ThemeFns has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class ThemeFns {
    
        private ThemeFns() {
        }
    
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 3 hrs to fix

      Method grad has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static String grad(String dir, Browser template, String[] colors) {
              if ("|ver|hor|diag-|diag+|rad|".indexOf("|" + dir + "|") == -1)
                  throw new IllegalArgumentException("Type must be ver, hor, diag-, diag+, or rad.");
              if (colors.length < 2)
                  throw new IllegalArgumentException("Please specify more than two colors.");
      Severity: Major
      Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 2 hrs to fix

        Method getBrowser has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static Browser getBrowser() {
                Double number = Servlets.getBrowser(ServletFns.getCurrentRequest(), "ff");
                if (number != null && number >= 3.6)
                    return Browser.Firefox;
                number = Servlets.getBrowser(ServletFns.getCurrentRequest(), "ie");
        Severity: Minor
        Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 1 hr to fix

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

              public static String getCurrentTheme() {
                  // 1. cookie's key
                  String t = getTheme();
                  if (_themeRegistry.hasTheme(t))
                      return t;
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.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 box3 has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public static String box3(String styleName, String styleValue, String styleName2, String styleValue2,
                      String styleName3, String styleValue3) {
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 45 mins to fix

            Avoid too many return statements within this method.
            Open

                                return Browser.WebKit;
            Severity: Major
            Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return Browser.Opera;
              Severity: Major
              Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return Browser.WebKit;
                Severity: Major
                Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return Browser.Old_WebKit;
                  Severity: Major
                  Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return Browser.Old;
                    Severity: Major
                    Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return Browser.WebKit;
                      Severity: Major
                      Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                            return Browser.Old_WebKit;
                        Severity: Major
                        Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java - About 30 mins to fix

                          Method toHex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @SuppressWarnings("unchecked")
                              private static String toHex(String color) {
                                  color = color.trim();
                                  if (color.startsWith("#")) {
                                      int end = color.indexOf(" ");
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.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 toIEHex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @SuppressWarnings("unchecked")
                              private static String toIEHex(String color) {
                                  color = color.trim();
                                  if (color.startsWith("#")) {
                                      int end = color.indexOf(" ");
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.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

                              @SuppressWarnings("unchecked")
                              private static String toHex(String color) {
                                  color = color.trim();
                                  if (color.startsWith("#")) {
                                      int end = color.indexOf(" ");
                          Severity: Major
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 2 hrs to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 379..399

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

                          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

                              @SuppressWarnings("unchecked")
                              private static String toIEHex(String color) {
                                  color = color.trim();
                                  if (color.startsWith("#")) {
                                      int end = color.indexOf(" ");
                          Severity: Major
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 2 hrs to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 353..373

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

                          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

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

                                          if (end == 0 && !color.toLowerCase(java.util.Locale.ENGLISH).contains("transparent"))
                                              if (hex)
                                                  throw new IllegalArgumentException(
                                                          "The format of hexadecimal is wrong! [" + color + "] or without stops (%)");
                                              else
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 50 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 174..180

                          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

                          Further Reading

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

                                          if (end == 0 && !color.toLowerCase(java.util.Locale.ENGLISH).contains("transparent"))
                                              if (hex)
                                                  throw new IllegalArgumentException(
                                                          "The format of hexadecimal is wrong! [" + color + "] or without stops (%)");
                                              else
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 50 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 153..159

                          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

                          Further Reading

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

                                          if ("W3C".equals(browser)) {
                                              _GRAD_TYPE = new HashMap<String, String>();
                                              _GRAD_TYPE.put("ver", "to bottom");
                                              _GRAD_TYPE.put("hor", "to right");
                                              _GRAD_TYPE.put("diag-", "135deg");
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 50 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 491..498

                          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

                          Further Reading

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

                                          } else {
                                              _GRAD_TYPE = new HashMap<String, String>();
                                              _GRAD_TYPE.put("ver", "top");
                                              _GRAD_TYPE.put("hor", "left");
                                              _GRAD_TYPE.put("diag-", "-45deg");
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 1 other location - About 50 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 484..491

                          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

                          Further Reading

                          Identical blocks of code found in 3 locations. Consider refactoring.
                          Open

                                  if (browser == Browser.Firefox || browser == Browser.WebKit) {
                                      sb.append("\t display:\t").append(browser.getPrefix()).append("box;\n");
                                  }
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 2 other locations - About 30 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 294..296
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 312..314

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

                          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

                          Identical blocks of code found in 3 locations. Consider refactoring.
                          Open

                                  if (browser == Browser.Firefox || browser == Browser.WebKit) {
                                      sb.append("\t display:\t").append(browser.getPrefix()).append("box;\n");
                                  }
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 2 other locations - About 30 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 278..280
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 294..296

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

                          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

                          Identical blocks of code found in 3 locations. Consider refactoring.
                          Open

                                  if (browser == Browser.Firefox || browser == Browser.WebKit) {
                                      sb.append("\t display:\t").append(browser.getPrefix()).append("box;\n");
                                  }
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java and 2 other locations - About 30 mins to fix
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 278..280
                          zweb/src/main/java/org/zkoss/web/fn/ThemeFns.java on lines 312..314

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

                          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