weexteam/weex_devtools_android

View on GitHub
inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java

Summary

Maintainability
D
2 days
Test Coverage

Method getValueForField has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

  private Object getValueForField(Field field, Object value)
      throws JSONException {
    try {
      if (value != null) {
        if (value == JSONObject.NULL) {

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 ObjectMapper.java has 274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright (c) 2014-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the

    Method convertArrayToList has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      private List<Object> convertArrayToList(Field field, JSONArray array)
          throws IllegalAccessException, JSONException {
        if (List.class.isAssignableFrom(field.getType())) {
          ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
          Type[] types = parameterizedType.getActualTypeArguments();

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

      private Object getValueForField(Field field, Object value)
          throws JSONException {
        try {
          if (value != null) {
            if (value == JSONObject.NULL) {

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

        private JSONObject _convertToJSONObject(Object fromValue)
            throws JSONException, InvocationTargetException, IllegalAccessException {
          JSONObject jsonObject = new JSONObject();
      
          if(fromValue instanceof Map) {

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

        public <T> T convertValue(Object fromValue, Class<T> toValueType)
            throws IllegalArgumentException {
          if (fromValue == null) {
            return null;
          }

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

        private List<Object> convertArrayToList(Field field, JSONArray array)
            throws IllegalAccessException, JSONException {
          if (List.class.isAssignableFrom(field.getType())) {
            ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
            Type[] types = parameterizedType.getActualTypeArguments();

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

          private Object getJsonValue(Object value, Class<?> clazz, Field field)
              throws InvocationTargetException, IllegalAccessException {
            if (value == null) {
              // Now technically we /could/ return JsonNode.NULL here but Chrome's webkit inspector croaks
              // if you pass a null "id"

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

          public <T> T convertValue(Object fromValue, Class<T> toValueType)
              throws IllegalArgumentException {
            if (fromValue == null) {
              return null;
            }

          Method getEnumByMethod has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            private Enum getEnumByMethod(String value, Class<? extends Enum> clazz, Method method) {
              Enum[] enumValues = clazz.getEnumConstants();
              // Start at the front to ensure first always wins
              for (int i = 0; i < enumValues.length; ++i) {
                Enum enumValue = enumValues[i];
          Severity: Minor
          Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.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

          Avoid too many return statements within this method.
          Open

                  return "-Infinity";
          Severity: Major
          Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return convertArrayToList(field, (JSONArray) value);
            Severity: Major
            Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return value;
              Severity: Major
              Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                              return numberValue.longValue();
                Severity: Major
                Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                      return value;
                  Severity: Major
                  Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                  return numberValue.intValue();
                    Severity: Major
                    Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return "Infinity";
                      Severity: Major
                      Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                      return numberValue.floatValue();
                        Severity: Major
                        Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                        return numberValue.doubleValue();
                          Severity: Major
                          Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return "NaN";
                            Severity: Major
                            Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return getEnumValue((String) value, field.getType().asSubclass(Enum.class));
                              Severity: Major
                              Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                          return convertValue(value, field.getType());
                                Severity: Major
                                Found in inspector/src/main/java/com/taobao/weex/devtools/json/ObjectMapper.java - About 30 mins to fix

                                  There are no issues that match your filters.

                                  Category
                                  Status