ForestAdmin/forest-express-mongoose

View on GitHub

Showing 63 of 66 total issues

Function init has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

exports.init = (opts) => {
  exports.opts = opts;

  if (!opts.objectMapping) {
    Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
Severity: Minor
Found in src/index.js - About 1 day 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 FiltersParser has 183 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function FiltersParser(model, timezone, options) {
  const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];

  const parseInteger = (value) => Number.parseInt(value, 10);
  const parseDate = (value) => new Date(value);
Severity: Major
Found in src/services/filters-parser.js - About 7 hrs to fix

    Function FiltersParser has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    function FiltersParser(model, timezone, options) {
      const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];
    
      const parseInteger = (value) => Number.parseInt(value, 10);
      const parseDate = (value) => new Date(value);
    Severity: Minor
    Found in src/services/filters-parser.js - 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

    Function init has 116 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.init = (opts) => {
      exports.opts = opts;
    
      if (!opts.objectMapping) {
        Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
    Severity: Major
    Found in src/index.js - About 4 hrs to fix

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

          getUser(customerModel, customerField, customerId) {
            return new P((resolve, reject) => {
              if (customerId) {
                return customerModel
                  .findById(customerId)
      Severity: Major
      Found in src/index.js and 1 other location - About 4 hrs to fix
      src/index.js on lines 89..104

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

      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

          getCustomer(customerModel, customerField, customerId) {
            return new P((resolve, reject) => {
              if (customerId) {
                return customerModel
                  .findById(customerId)
      Severity: Major
      Found in src/index.js and 1 other location - About 4 hrs to fix
      src/index.js on lines 154..169

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

      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

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

        async perform() {
          const params = await getScopedParams(this._params, this._model, this._user);
          const timezone = -parseInt(moment().tz(params.timezone).format('Z'), 10);
          const timezoneOffset = timezone * 60 * 60 * 1000;
          const queryBuilder = new QueryBuilder(this._model, params, this._opts);
      Severity: Major
      Found in src/services/line-stat-getter.js - About 3 hrs to fix

        Function SearchBuilder has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function SearchBuilder(model, opts, params, searchFields) {
          const schema = Interface.Schemas.schemas[utils.getModelName(model)];
          const fieldsSearched = [];
        
          this.hasSmartFieldSearch = false;
        Severity: Major
        Found in src/services/search-builder.js - About 3 hrs to fix

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

            _handlePopulate(query) {
              const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
          
              _.each(schema.fields, (field) => {
                if (field.reference) {
          Severity: Major
          Found in src/services/has-many-getter.js and 1 other location - About 3 hrs to fix
          src/services/resource-getter.js on lines 14..21

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

          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

            _handlePopulate(query) {
              const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
              _.each(schema.fields, (field) => {
                if (field.reference) {
                  query.populate({ path: field.field, strictPopulate: false });
          Severity: Major
          Found in src/services/resource-getter.js and 1 other location - About 3 hrs to fix
          src/services/has-many-getter.js on lines 47..58

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

          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

          Function getConditions has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            this.getConditions = async () => {
              this.hasSmartFieldSearch = false;
              const orQuery = { $or: [] };
          
              function pushCondition(condition, fieldName) {
          Severity: Major
          Found in src/services/search-builder.js - About 3 hrs to fix

            exports has 26 functions (exceeds 20 allowed). Consider refactoring.
            Open

            module.exports = class Flattener {
              constructor(schema, flatten, model, lianaOptions) {
                this.schema = schema;
                this.flatten = flatten;
                this.model = model;
            Severity: Minor
            Found in src/services/flattener.js - About 3 hrs to fix

              File flattener.js has 280 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import _ from 'lodash';
              import Interface from 'forest-express';
              import FieldIntrospector from '../utils/field-analyser';
              import { getMongooseSchemaFromFieldPath } from '../utils/schema';
              
              
              Severity: Minor
              Found in src/services/flattener.js - About 2 hrs to fix

                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

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

                        return moment()
                          .year(record._id.year)
                          .month(record._id.month - 1)
                          .startOf('month')
                          .add(record._id.day - 1, 'days')
                Severity: Major
                Found in src/services/line-stat-getter.js and 1 other location - About 2 hrs to fix
                src/services/line-stat-getter.js on lines 37..42

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

                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

                        return moment()
                          .year(record._id.year)
                          .month(record._id.month - 1)
                          .startOf('month')
                          .add(record._id.day - 1, 'days')
                Severity: Major
                Found in src/services/line-stat-getter.js and 1 other location - About 2 hrs to fix
                src/services/line-stat-getter.js on lines 66..71

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

                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

                Function formatConditionForReferences has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  this.formatConditionForReferences = async (condition) => {
                    if (_.isEmpty(condition)) {
                      throw new InvalidFiltersFormatError('Empty condition in filter');
                    }
                    if (!_.isObject(condition)) {
                Severity: Major
                Found in src/services/filters-parser.js - About 2 hrs to fix

                  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

                    Severity
                    Category
                    Status
                    Source
                    Language