ForestAdmin/forest-express-mongoose

View on GitHub
src/utils/field-analyser.js

Summary

Maintainability
D
2 days
Test Coverage
A
95%

Function _getTypeFromMongoose has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  _getTypeFromMongoose(fieldInfo) {
    if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
      // Deal with Object
      return this._objectType(
        fieldInfo,
Severity: Minor
Found in src/utils/field-analyser.js - About 3 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

Function _getTypeFromNative has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  _getTypeFromNative(type) {
    if (type instanceof Array) {
      if (_.isEmpty(type)) {
        return [null];
      }
Severity: Minor
Found in src/utils/field-analyser.js - About 2 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

Function _getTypeFromMongoose has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  _getTypeFromMongoose(fieldInfo) {
    if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
      // Deal with Object
      return this._objectType(
        fieldInfo,
Severity: Minor
Found in src/utils/field-analyser.js - About 1 hr to fix

    Function _detectReference has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      _detectReference(fieldInfo) {
        if (fieldInfo.options) {
          if (fieldInfo.options.ref && fieldInfo.options.type) {
            const ref = this._formatRef(fieldInfo.options.ref);
            return ref ? `${ref}._id` : null;
    Severity: Minor
    Found in src/utils/field-analyser.js - 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

    Function _getValidations has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static _getValidations(fieldInfo) {
        const validations = [];
    
        if (fieldInfo.validators && fieldInfo.validators.length > 0) {
          _.each(fieldInfo.validators, (validator) => {
    Severity: Minor
    Found in src/utils/field-analyser.js - About 1 hr to fix

      Function _getTypeFromNative has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _getTypeFromNative(type) {
          if (type instanceof Array) {
            if (_.isEmpty(type)) {
              return [null];
            }
      Severity: Minor
      Found in src/utils/field-analyser.js - About 1 hr to fix

        Function getFieldSchema has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          getFieldSchema(path, fieldInfo) {
            const schema = { field: path, type: this._getTypeFromMongoose(fieldInfo) };
        
            const ref = this._detectReference(fieldInfo);
            if (ref) { schema.reference = ref; }
        Severity: Minor
        Found in src/utils/field-analyser.js - About 1 hr to fix

          Function getFieldSchema has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            getFieldSchema(path, fieldInfo) {
              const schema = { field: path, type: this._getTypeFromMongoose(fieldInfo) };
          
              const ref = this._detectReference(fieldInfo);
              if (ref) { schema.reference = ref; }
          Severity: Minor
          Found in src/utils/field-analyser.js - 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

          Avoid too many return statements within this function.
          Open

                  return 'Json';
          Severity: Major
          Found in src/utils/field-analyser.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return this._schemaType(type);
            Severity: Major
            Found in src/utils/field-analyser.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return null;
              Severity: Major
              Found in src/utils/field-analyser.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return 'Json';
                Severity: Major
                Found in src/utils/field-analyser.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return 'String';
                  Severity: Major
                  Found in src/utils/field-analyser.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return this._getTypeFromNative(type.type);
                    Severity: Major
                    Found in src/utils/field-analyser.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return [this._objectType(fieldInfo.options.type[0], (key) =>
                              this._getTypeFromNative(fieldInfo.options.type[0][key]))];
                      Severity: Major
                      Found in src/utils/field-analyser.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return 'String';
                        Severity: Major
                        Found in src/utils/field-analyser.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return [this._getTypeFromNative(fieldInfo.options.type[0])];
                          Severity: Major
                          Found in src/utils/field-analyser.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return 'Enum';
                            Severity: Major
                            Found in src/utils/field-analyser.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                  return fieldInfo.instance
                                    || (fieldInfo.options && this._getTypeFromNative(fieldInfo.options.type))
                                    || null;
                              Severity: Major
                              Found in src/utils/field-analyser.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return this._objectType(fieldInfo.schema.obj, (fieldName) =>
                                        this._getTypeFromNative(fieldInfo.schema.obj[fieldName]));
                                Severity: Major
                                Found in src/utils/field-analyser.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return this._objectType(type, (key) => this._getTypeFromNative(type[key]));
                                  Severity: Major
                                  Found in src/utils/field-analyser.js - About 30 mins to fix

                                    There are no issues that match your filters.

                                    Category
                                    Status