zk/src/main/java/org/zkoss/zk/device/Devices.java

Summary

Maintainability
D
1 day
Test Coverage

File Devices.java has 314 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* Devices.java

    Purpose:
        
    Description:
Severity: Minor
Found in zk/src/main/java/org/zkoss/zk/device/Devices.java - About 3 hrs to fix

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

        public static final Device getDeviceByClient(String userAgent) throws DeviceNotFoundException {
            String[] devTypes;
            synchronized (_devmap) {
                Collection<String> c = _devmap.keySet();
                devTypes = c.toArray(new String[c.size()]);
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/device/Devices.java - About 1 hr 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 getDeviceByClient has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static final Device getDeviceByClient(String userAgent) throws DeviceNotFoundException {
            String[] devTypes;
            synchronized (_devmap) {
                Collection<String> c = _devmap.keySet();
                devTypes = c.toArray(new String[c.size()]);
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/device/Devices.java - About 1 hr to fix

      Method addEmbedded has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public static void addEmbedded(String deviceType, String content) {
              if (deviceType == null || deviceType.length() == 0)
                  throw new IllegalArgumentException();
              if (content == null || content.length() == 0)
                  return; //nothing to do
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java - About 1 hr 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 setUnavailableMessage has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public static final String setUnavailableMessage(String deviceType, String msg) {
              if (deviceType == null || deviceType.length() == 0)
                  throw new IllegalArgumentException();
      
              if (msg != null && msg.length() == 0)
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java - About 1 hr 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 setServerPushClass0 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          private static final String setServerPushClass0(String deviceType, Object cls) {
              if (deviceType == null || deviceType.length() == 0)
                  throw new IllegalArgumentException();
      
              try {
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.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 getDevice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public static final Device getDevice(String deviceType) throws DeviceNotFoundException {
              final Object o; //null, Device or DeviceInfo
              synchronized (_devmap) {
                  o = _devmap.get(deviceType);
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.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 newDevice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              private Device newDevice(String deviceType) {
                  if (_dvcls == null) //possible
                      throw new DeviceNotFoundException(deviceType, MZk.NOT_FOUND, deviceType);
      
                  try {
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.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 String getEmbedded(String deviceType) {
              final Object o;
              synchronized (_devmap) {
                  o = _devmap.get(deviceType);
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 50 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 238..245

      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

          public static final String getUnavailableMessage(String deviceType) {
              final Object o;
              synchronized (_devmap) {
                  o = _devmap.get(deviceType);
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 50 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 280..287

      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 if (o instanceof DeviceInfo) {
                          return ((DeviceInfo) o).setServerPushClass(cls);
                      } else {
                          final DeviceInfo info = new DeviceInfo();
                          _devmap.put(deviceType, info);
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 40 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 264..271

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

      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 if (o instanceof DeviceInfo) {
                      return ((DeviceInfo) o).setUnavailableMessage(msg);
                  } else {
                      final DeviceInfo info = new DeviceInfo();
                      _devmap.put(deviceType, info);
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 40 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 373..380

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

      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

              public void addEmbedded(String content) {
                  if (content != null && content.length() > 0)
                      _embed = _embed != null ? _embed + '\n' + content : content;
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 40 mins to fix
      zk/src/main/java/org/zkoss/zk/device/GenericDevice.java on lines 83..86

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

      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

              public String setUnavailableMessage(String msg) {
                  final String old = _uamsg;
                  _uamsg = msg != null && msg.length() > 0 ? msg : null;
                  return old;
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 35 mins to fix
      zk/src/main/java/org/zkoss/zk/device/GenericDevice.java on lines 59..63

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

      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

              private String setDeviceClass(Object cls) {
                  final Object old = _dvcls;
                  _dvcls = cls;
                  return old instanceof Class ? ((Class) old).getName() : (String) old;
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 30 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 483..487

      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

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

              public String setServerPushClass(Object cls) {
                  final Object old = _spushcls;
                  _spushcls = cls;
                  return old instanceof Class ? ((Class) old).getName() : (String) old;
              }
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/device/Devices.java and 1 other location - About 30 mins to fix
      zk/src/main/java/org/zkoss/zk/device/Devices.java on lines 464..468

      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